入门模拟——(字符串处理)B1009.说反话
#include <bits/stdc++.h> #include<math.h> using namespace std; const int MAX_LEN = 105; //const int MAX_D = 31; //char temp[MAX_LEN]; //vector<char> result; //char temp1[120]; int main(){ /*temp1[0] =' '; for(int i =1;i<MAX_LEN;++i){ temp[i] = '9'; } cin>>temp; strcat(temp1,temp); for(int i=MAX_LEN;i<120;++i){ temp1[i] = '9'; } int fir=0; int sec=0; for(int i=119;i>=0;i = sec - 2){ fir = i; while(temp1[fir] == '9'){ fir--; } sec = fir; while(temp1[sec-1] != ' '){ sec--; } int firtemp = fir; int sectemp = sec; for(int i=sec;i<=fir;++i){ char t = temp1[i]; result.push_back(t); } result.push_back(' '); } for(int i=0;i<result.size()-1;++i){ cout<<result[i]; }*/ char str[90]; gets(str); int len = strlen(str), r =0,h=0;//r为行,h为列 char ans[90][90];//ans[r] 存放单词 for(int i =0;i<len;++i){ if(str[i] != ' '){ ans[r][h++] = str[i]; }else{ r++; h = 0; ans[r][h] = '\0'; } } for(int i = r;i>=0;--i){ cout<<ans[i]; if(i > 0){ cout<<" "; } } system("pause"); return 0; }