Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
58007 王嘉瑜 单词翻转 C++ Accepted 3 MS 284 KB 513 2023-09-16 21:02:05

Tests(10/10):


Code:

#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; }