题意:如题。
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
void deal(string& line, int start, int end)
{
end -= 1;
while (start < end)
{
line[start] ^= line[end] ^= line[start] ^= line[end];
start++, end--;
}
}
void result(string& line)
{
int start, end = 0;
bool flag = false;
while (1)
{
start = line.find_first_not_of(' ', end);
if (start == string::npos)
return;
end = line.find_first_of(' ', start);
if (end == string::npos)
{
flag = true;
end = line.length();
}
deal(line, start, end);
if (flag) return;
}
}
int main()
{
int n;
cin >> n;
getchar();
string line;
while (n--)
{
getline(cin, line);
result(line);
cout << line << endl;
}
return 0;
}
1481

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



