"尚學堂杯"哈爾濱理工大學第七屆程式設計競賽 F Final Ugly English
阿新 • • 發佈:2019-02-08
F.Final Ugly English | |||||
|
|||||
Description | |||||
ACM twist-toy encountered such a problem in the work, this article, to ensure that this article only lowercase letters and spaces, please send the articles in each word inverted output, such as "hello world this is an competition". You should output "olleh dlrow siht si na noititepmoc". |
|||||
Input | |||||
A group of data, each line of data input from the lower case letters and spaces of the article, the length of not more than one thousand |
|||||
Output | |||||
Output a line for each word after the reversal of the article. |
|||||
Sample Input | |||||
hello world this is an competition | |||||
Sample Output | |||||
olleh dlrow siht si na noititepmoc |
一遇到這種題就gg了,,一定得好好補補這種題型
注意:1。多組輸入。2.輸出後得字串無空格
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> using namespace std; string a; /ar b[1005]; int main() { while(getline(cin,a)) { int len=a.size(); //printf("%d\n",len); int j=0,k=0; for(int i=0; i<=len; i++) { //printf("%d\n",a[i]); if(a[i]<'a'||a[i]>'z') { //printf("%d \n",i); for(j=i-1; j>=k; j--) { printf("%c",a[j]); } k=i+1; if(i<len) printf(" "); } } printf("\n"); } return 0; }