B1009 说反话 重要 P65下
//B1009 说反话 重要 P65下
#include <iostream>
#include <string>
using namespace std;
int main(){
string s;
getline(cin,s);
while(s.length() > 0){
int i = s.rfind(' '); //从右向左找
if(i != string::npos){
cout<<s.substr(i+1)<<" ";
string temp = s.substr(0,i);
s = temp;
}else{
cout<<s<<endl;
s="";
}
}
return 0;
} C:
#include <stdio.h>
#include <string.h>
#define maxSize 100
void reverse(int left,int right,char a[]){
for(int i=left,j=right;i<j;++i,--j){
char temp;
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
int main() {
char str[maxSize];
gets(str);//warning: this program uses gets(), which is unsafe.
int len = strlen(str);
reverse(0,len-1,str);
int i=0,j=0;
while(1){
while (str[j] != ' ' && str[j] != '\0') ++j;
reverse(i,j-1,str);
if(str[j] == '\0') break;
++j;
i = j;
}
puts(str);
return 0;
} 

