counting

Convert/cast CFReadStreamRef to NSInputStream (iOS5)

北慕城南 提交于 2019-12-02 04:05:30
问题 I am trying to port my app to iOS5. I am using a TCP connection to a server via CFSockets. My problem now is the conversion (cast) from CFReadStreamRef to NSInputStream (same with write). With iOS4 I could use the toll-free bridging, but with automatic reference counting of iOS5 this isn't possible anymore. This is what I get: error: Automatic Reference Counting Issue: Cast to 'NSInputStream *' of a non-Objective-C to an Objective-C pointer is disallowed with Automatic Reference Counting Code

python counting letters in string without count function

本小妞迷上赌 提交于 2019-12-02 03:12:19
I am trying to write a program to count the occurrences of a specific letter in a string without the count function. I made the string into a list and set a loop to count but the count is never changing and i cant figure out why. This is what I have right now: letter = 'a' myString = 'aardvark' myList = [] for i in myString: myList.append(i) count = 1 for i in myList: if i == letter: count == count + 1 else: continue print (count) Any help is greatly appreciated. Be careful, you are using count == count + 1 , and you must use count = count + 1 The operator to attribute a new value is = , the

python counting letters in string without count function

天大地大妈咪最大 提交于 2019-12-02 01:49:29
问题 I am trying to write a program to count the occurrences of a specific letter in a string without the count function. I made the string into a list and set a loop to count but the count is never changing and i cant figure out why. This is what I have right now: letter = 'a' myString = 'aardvark' myList = [] for i in myString: myList.append(i) count = 1 for i in myList: if i == letter: count == count + 1 else: continue print (count) Any help is greatly appreciated. 回答1: Be careful, you are

Convert/cast CFReadStreamRef to NSInputStream (iOS5)

霸气de小男生 提交于 2019-12-02 00:36:29
I am trying to port my app to iOS5. I am using a TCP connection to a server via CFSockets. My problem now is the conversion (cast) from CFReadStreamRef to NSInputStream (same with write). With iOS4 I could use the toll-free bridging, but with automatic reference counting of iOS5 this isn't possible anymore. This is what I get: error: Automatic Reference Counting Issue: Cast to 'NSInputStream *' of a non-Objective-C to an Objective-C pointer is disallowed with Automatic Reference Counting Code: CFReadStreamRef readStream; CFWriteStreamRef writeStream; CFStringRef strRef =

How to code a C++ program which counts the number of uppercase letters, lowercase letters and integers in an inputted string?

风格不统一 提交于 2019-12-01 14:54:50
I'm looking for a simple and basic way (ideal for beginners to learn the easiest way) to write a program in C++ which gets a string from the user and outputs the number of uppercase letters, lowercase letters and integers (numbers). I'm pretty amateur at using C++ syntax so please help me with an easy-to-understand syntax. Thanks! EDIT: Here is a very simple code that I found in Google and did some changes and corrections: #include <iostream> #include <conio.h> using namespace std; int main() { char array1[50]; int i = 0, lowercase = 0, uppercase = 0, numbers = 0, total; cout << "Enter a

Understanding `sort!` block

☆樱花仙子☆ 提交于 2019-12-01 13:02:34
问题 Right now I have an array letter = ['a','b','c','a','b','c','a','b','b'] Can someone kindly explain the following return value? letter.sort! { |x| letter.count(x) } #=> ["b", "b", "a", "c", "c", "a", "b", "b", "a"] 回答1: When you define a sort or sort! block you are obligated to take in two arguments, typically a and b . These are the two elements the sort operation is comparing at the time, so this block will be called repeatedly with various pairs. There are constraints imposed on what you

How to detect and count a spiral's turns

旧街凉风 提交于 2019-12-01 05:18:13
I need to detect a spiral shaped spring and count its coil turns. I have tried as follows: Image<Bgr, Byte> ProcessImage(Image<Bgr, Byte> img) { Image<Bgr, Byte> imgClone = new Image<Bgr,byte>( img.Width, img.Height); imgClone = img.Clone(); Bgr bgrRed = new Bgr(System.Drawing.Color.Red); #region Algorithm 1 imgClone.PyrUp(); imgClone.PyrDown(); imgClone.PyrUp(); imgClone.PyrDown(); imgClone.PyrUp(); imgClone.PyrDown(); imgClone._EqualizeHist(); imgClone._Dilate(20); imgClone._EqualizeHist(); imgClone._Erode(10); imgClone.PyrUp(); imgClone.PyrDown(); imgClone.PyrUp(); imgClone.PyrDown();

count the number of occurrences of a certain value in a dictionary in python?

我只是一个虾纸丫 提交于 2019-11-30 23:41:16
问题 If I have got something like this: D = {'a': 97, 'c': 0 , 'b':0,'e': 94, 'r': 97 , 'g':0} If I want for example to count the number of occurrences for the "0" as a value without having to iterate the whole list, is that even possible and how? 回答1: As I mentioned in comments you can use a generator within sum() function like following: sum(value == 0 for value in D.values()) Or as a slightly more optimized and functional approach you can use map function as following: sum(map((0).__eq__, D

Counting the number of occurrences of a string within a string

浪尽此生 提交于 2019-11-30 23:27:41
What's the best way of counting all the occurrences of a substring inside a string? Example: counting the occurrences of Foo inside FooBarFooBarFoo One way to do is to use std::string find function: #include <string> #include <iostream> int main() { int occurrences = 0; std::string::size_type pos = 0; std::string s = "FooBarFooBarFoo"; std::string target = "Foo"; while ((pos = s.find(target, pos )) != std::string::npos) { ++ occurrences; pos += target.length(); } std::cout << occurrences << std::endl; } #include <iostream> #include <string> // returns count of non-overlapping occurrences of

Counting digits using while loop

血红的双手。 提交于 2019-11-30 20:20:09
I was recently making a program which needed to check the number of digits in a number inputted by the user. As a result I made the following code: int x; cout << "Enter a number: "; cin >> x; x /= 10; while(x > 0) { count++; x = x/10; } From what I can tell (even with my limited experience) is that it seems crude and rather unelegant. Does anyone have an idea on how to improve this code (while not using an inbuilt c++ function)? In your particular example you could read the number as a string and count the number of characters. But for the general case, you can do it your way or you can use a