And this is how I write the program, which will be checked by the computer, and the problem is that on my local machine everything works in normal mode, but when I load into the system I get a Time limit exception for all tests. I attach the task itself and its code. (And yes, read the task character by character). enter image description here

enter image description here

  • And why did you decide that the string always ends with \n ? - Harry
  • Data entry format - A series of characters ending with a CHANGE TRANSFER SYMBOL. )) - MrLalatg
  • And, yes, did not pay attention ... And if the line is empty, what will happen? One \n and nothing else ? - Harry

2 answers 2

Formal answer:

Your code does not work if the input string is empty, i.e. if all input is just one \n .

However, I would act like this:

 string s; getline(cin,s); int result = 0; for(auto c: s) if (isdigit(c)) ++result; cout << result << endl; 
  • The fact is that the Time limit happens with any test, even when a normal string is entered ... (I have a list of tests not passed) - MrLalatg
  • List of tests - MrLalatg
  • Do not give the URL? Sign in and see? - Harry
  • Unfortunately, you will not be allowed to enter without an account, this is the Yandex SMR, you must enter it in order to receive the assignment ... - MrLalatg
  • Well, try my version ... - Harry

Thanks to the idea of ​​Harry, I got something like this:

 int result = 0; for(char i = cin.get(); i!='\n'; i = cin.get()){ if(isdigit(i)){ result++; } } cout<<result; return 0;