有是一个字符串翻转问题,唉,自以为处理的很巧妙,因为如果整句输入可能真的不好处理,呵呵,反正没这样简单!
code:
#include <cstring>
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int t,j=1;
char k;
cin >> t;
getchar();
while (1) {
if (j > t)
break;
string p;
cin >> p;
reverse(p.begin(), p.end()); //hehe,输入一个转换一个
cout << p;
k = getchar();
if (k ==' ')
cout <<" ";
if (k == '\n') { //有换行我就处理下一行
j++;
cout << endl;
}
}
if (n)
cout << endl;
}
}
本文介绍了一个简单的字符串翻转程序,该程序使用C++编写,并利用了标准库中的<algorithm>进行字符串翻转操作。通过逐个读取输入并立即翻转显示,实现了即时反馈。
805

被折叠的 条评论
为什么被折叠?



