HDOJ 1062:字符串翻转问题
3 月,跳不动了?>>> 题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=1062 一、题目要求 现有若干行输入,每行输入都有若干个字符串,每个字符串中间都间隔了若干个空格 读入这些输入后,将其按原有格式输出(即空格与回车字符位置不变),但每个字符串都要被翻转 二、题目代码 #include<iostream> using namespace std; int main() { int count; //文字行数 int curr; //用于遍历读入的一行文字 string s; //读取的一行文字 string temp; //临时存储一小段连续的不含空格的文字 cin >> count; getchar(); //读取count后面的'\n' while(count--) { getline(cin, s); temp = ""; for(curr = 0; curr < s.length(); curr++) { //读入到最后一个字符,输出最后一个字符串的翻转 if(curr == s.length() - 1 && s[curr] != ' ') { temp = s[curr] + temp; cout << temp; } //读入到空格后,输出上一个字符串的翻转 else if(s[curr] == ' ') {