原题链接:http://ac.jobdu.com/problem.php?pid=1525
字符串简单题,注意开有结尾有空格的情况否则pe or wa
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
using std::string;
using std::vector;
using std::cin;
const int Max_N = ;
char buf[Max_N], temp[Max_N];
void reverse(char *src, int n){
int i, j = n - ;
for (i = ; i < j; i++, j--){
char tp = src[i];
src[i] = src[j];
src[j] = tp;
}
}
void solve(int n){
int i, j;
vector<string> ans;
for (i = ; i < n; i++){
if (buf[i] != ' ' || !i){
j = ;
for (; buf[i] != ' ' && i < n; i++) temp[j++] = buf[i];
temp[j] = '\0';
reverse(temp, j);
ans.push_back(temp);
}
}
if (buf[n - ] == ' ') ans.push_back("");
int t = ans.size();
for (i = ; i < t; i++){
printf("%s%c", ans[i].c_str(), i < t - ? ' ' : '\n');
}
}
int main(){
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int n;
while (~scanf("%d", &n) && n){
while (getchar() != '\n');
gets(buf);
solve(n);
}
return ;
}