团体程序设计天梯赛-练习集(七)(7-32 说反话-加强版)
作者:互联网
7-32 说反话-加强版 (20分)
https://pintia.cn/problem-sets/14/problems/812
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <string> 5 #include <cmath> 6 #include <algorithm> 7 using namespace std; 8 int main() 9 { 10 string str; 11 getline(cin,str); 12 int len=str.length(); 13 int i,j,k; 14 int cnt=0,flag=1,start=0; 15 for(i=0;i<len;i++) 16 if(str[i]!=' ') 17 { 18 start=i; 19 break; 20 } 21 for(i=len-1;i>=0;i--) 22 { 23 if(str[i]!=' ') 24 { 25 flag=0; 26 cnt++; 27 } 28 else if(!flag) 29 { 30 flag=1; 31 for(j=i+1;j<i+1+cnt;j++) cout<<str[j]; 32 if(i+1!=start) cout<<" "; 33 cnt=0; 34 } 35 } 36 for(i=start;i<start+cnt;i++) cout<<str[i]; 37 cout<<endl; 38 return 0; 39 }
标签:cnt,加强版,int,32,flag,str,反话,include 来源: https://www.cnblogs.com/jianqiao123/p/12127388.html