pat(B)1009. 说反话(逆迭代器)
代码:
#include<cstdio> #include<cstring> #include<iostream> #include<string> #include<vector> using namespace std; char s[1000]; vector<string> vec; int main() { while(gets(s)) { string ss=""; vec.clear(); int len=strlen(s); s[len]=' '; for(int i=0; i<=len; i++) { if(s[i]!=' ') ss+=s[i]; else { vec.push_back(ss); ss=""; } } vector<string>::reverse_iterator it; for(it=vec.rbegin(); it!=vec.rend(); it++) { if(it==vec.rbegin()) cout<<*it; else cout<<" "<<*it; } cout<<endl; } return 0; }