#include <bits/stdc++.h>
using namespace std;
vector<string> split(string str, char delimiter)
{
vector<string> internal;
stringstream ss(str);
string tok;
while(getline(ss, tok, delimiter))
{
internal.push_back(tok);
}
return internal;
}
int main()
{
freopen("in", "r", stdin);
freopen("out", "w", stdout);
int tt;
scanf("%d", &tt);
for (int qq = 1; qq <= tt; qq++) {
printf("Case #%d: ", qq);
char s[1234];
stringstream ss;
gets(s);
for(int j = 0; s[j] ; j++) ss << s[j];
vector<string> w = split(ss.str(), ' ');
for(int i = 0; i < w.size(); ++i)
{
printf("%s ", w[i].c_str());
}
printf("\n");
}
return 0;
}
输入
5
this is a test
foobar
all your base
class
pony along
输出
Case #1:
Case #2: this is a test
Case #3: foobar
Case #4: all your base
Case #5: class
我是 C++ 初学者。我正在尝试解决反向单词问题:https ://code.google.com/codejam/contest/351101/dashboard#s=p1
我无法弄清楚为什么我的输出给出了这个。
请帮我。