hduoj Text Reverse
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062
这个老六啊我真的服了,一个cin和一个scanf都能给我卡,我真的服了,
其实这个题不是很难,这个题就是处理字符串逆序的板子甚至(自认为i)
处理逆序用字符串就ok了啊;
但是比较一下这两段代码:
#includeusing namespace std; int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; char ch; cin>>n; getchar(); while(n--) { stack<char>s; while(true) { ch=getchar(); if(ch==' '||ch=='\n') { while(!s.empty()) { printf("%c",s.top()); s.pop(); } if(ch=='\n') break; printf(" "); } else s.push(ch); } printf("\n"); } return 0; }
Talk is cheap. Show me the code.
AC代码:
1 #include2 using namespace std; 3 int main() 4 { 5 std::ios::sync_with_stdio(false); 6 cin.tie(0); 7 cout.tie(0); 8 int n; 9 char ch; 10 scanf("%d",&n); 11 getchar(); 12 while(n--) 13 { 14 stack<char>s; 15 while(true) 16 { 17 ch=getchar(); 18 if(ch==' '||ch=='\n') 19 { 20 while(!s.empty()) 21 { 22 printf("%c",s.top()); 23 s.pop(); 24 } 25 if(ch=='\n') 26 break; 27 printf(" "); 28 } 29 else 30 s.push(ch); 31 } 32 printf("\n"); 33 } 34 return 0; 35 }
看到了吧,第十行的输入用cin和scanf结果居然不一样我就离谱,真的,我得研究研究cin和scanf的一些细节问题;
就这样~~~~