http://acm.fzu.edu.cn/problem.php?pid=1054
This is a reverse string problem.
Ideas:
1. Number of input strings
2. Get the input string
3. Reverse, output.
The final AC code is as follows
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main () {
int number;
Char ch[220];
cin>>number;
GetChar ();
while (number--) {
gets (CH);
int len = strlen (ch);
for (int i = len-1;i>= 0;i--) {
cout<<ch[i];
}
cout<<endl;
}
return 0;
}
Compare the following code
The difference between the two pieces of code is that the position of the GetChar is different, but only the first one is AC.
Here is the difference between the two functions that do not understand GetChar and gets.
Gets
Receives a string of characters from the standard input, encounters ' \ n ' when it ends, but does not receive ' \ n ', holds ' \ n ' the input buffer, stores the received string of characters in the space that the form parameter pointer points to, and automatically adds a ' ".
GetChar
Receives a character return from the standard input, leaving the extra characters all in the input buffer.
In the title, the number only needs to be entered once, so use the GetChar, while the while loop will enter the string multiple times, so use gets.
So the GetChar in the while loop is obviously the wrong logic.