_h_a_p_p_y_'s blog

By _h_a_p_p_y_, history, 5 years ago, In English
  • Vote: I like it
  • +22
  • Vote: I do not like it

| Write comment?
»
5 years ago, hide # |
 
Vote: I like it +16 Vote: I do not like it
a = str.find(arr[i]);
if(a == -1)

Where to start from.... Error and your output clearly says that you don't print anything.
Let's see what find returns. It's returns value of type size_t, which is index of position if found or string::npos otherwize. npos is -1. Click

You assign size_t value to ll = long long. Problem 1 is size_t and long long not same types (first is unsigned type, second if signed). Problem 2 that is not guaranteed that they have same size.

In concrete your case it seems that size_t is unsigned int 32 type and long long is signed int 64. You assign -1 of unsigned int 32 which is 2^32 - 1 of unsigned int 32 to signed int 64 variable.

Assignment of different types. Right value must be converted to same type with left value before assignment. In the left signed int 64, in the right unsigned int 32. Right value type strictly smaller than left value type, so conversion can be made without loss. So after assignment a become 2^32 - 1 of signed int 64. And compare 2^32 - 1 of signed int 64 with -1 of signed int 32 never returns true. So you never print.

In other machines can be that size_t is unsigned int 64 and long long is signed int 64. Then rules are harder but in general in that case your code will work as expected.

Just do if (str.find(arr[i]) == string::npos) and it will print answer (left value is size_t and right value is size_t too).

P.S. Don't know why downvotes. Question is good and I guess there are many people that don't know about that problems.