Run ID:58007

提交时间:2023-09-16 21:02:05

#include <iostream> #include <string> using namespace std; int main(){ string s; getline(cin,s); int word_length = 0; for(int i=0;i<s.size();i++){ if(s[i]==' '){ // time to output // i for(int j=i-1;j>=i-word_length;j--) cout<<s[j]; cout<<' '; word_length = 0; } else{ word_length++; if(i==s.size()-1){ // end but no space // i for(int j=i;j>=i-word_length+1;j--) cout<<s[j]; break; } } } return 0; }