9 solutions
-
5
#include<bits/stdc++.h> using namespace std; string n; long x; int main(){ getline(cin,n); int sz=n.size(); for(int i=0; i<sz ;i++){ if(n[i]==' '){ for(int j=i-1;j>=x;j--) cout<<n[j]; cout<<' '; x=i+1; }else if(i+1>=sz){ for(int j=i;j>=x;j--){ cout<<n[j]; if(n[j]==n[sz-1]&&x==1) break; } } if(n[i-1]==' '||i==0) x=i; } return 0; }
完了,代码写长了
-
3
#include<iostream> #include<string> using namespace std; int main() { string a; getline(cin,a);//输入 a+=' '; string b="";//获取的单词 for(int i=0;i<a.length();i++) { if(a[i]==' ')//是否是单词间隔 { for(int j=b.length()-1;j>-1;j--)//反向输出 { cout<<b[j]; } cout<<" ";//空格! b=""; } else b+=a[i];//连接当前字符 } return 0;//完结散花! }
-
0
#include<bits/stdc++.h> using namespace std; int l,r; string a; int main(){ getline(cin,a); int len=a.length(); for(int i=0;i<=len;i++){ if(a[i]==' '){ r=i-1; for(int j=r;j>=l;j--){ cout<<a[j];} cout<<' '; l=r+2;} if(a[i]=='\0'){ r=i-1; for(int j=r;j>=l;j--){ cout<<a[j];} break;}} return 0;}
-
0
#include<bits/stdc++.h> using namespace std; int main() { string s, w[500]; int wi = 0, b = 0; getline(cin, s); for(int i = 0; i <= s.length(); ++i) { if(s[i] == ' ' || s[i] == '\0') { w[wi++] = s.substr(b, i-b);//截取字符串,从b开始截取i-b个字符 b = i+1; } } for(int i = 0; i < wi; ++i) { reverse(w[i].begin(),w[i].end());//将字符串s前后颠倒 cout << w[i] <<' '; } return 0; }
-
0
#include <bits/stdc++.h> using namespace std; string s; int main(int argc, char **argv){ getline(cin,s); int n = 0,len = s.length(); for(int i = 0;s[i];i++){ if (s[i] == ' '){ for(int j = i - 1;j >= i - n;j--){ cout << s[j]; } printf(" "); n = 0; }else{ n++; } } for(int i = len - 1;i >= (len - 1) - n;i--){ cout << s[i]; } return 0; }
- 1
Information
- ID
- 630
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 105
- Accepted
- 43
- Uploaded By