标签:
student. a am I I‘m a Freshman and I like JOBDU!
I am a student. JOBDU! like I and Freshman a I‘m
Code:
#include <iostream> #include <stack> using namespace std; int main() { string str; string seperator(" "); stack<string> words; while(getline(cin,str)){ string::size_type startPos=0,endPos=0; while(words.empty()==false) words.pop(); while((startPos=str.find_first_not_of(seperator,endPos))!=string::npos){ int spaceNum=startPos-endPos; int cnt=1; while(cnt<=spaceNum){ words.push(string(" ")); ++cnt; } endPos=str.find_first_of(seperator,startPos); string word; word.assign(str,startPos,endPos-startPos); words.push(word); } while(words.empty()==false){ string tmpWord=words.top(); words.pop(); cout<<tmpWord; } cout<<endl; } return 0; } /************************************************************** Problem: 1361 User: lcyvino Language: C++ Result: Accepted Time:260 ms Memory:1656 kb ****************************************************************/
标签:
原文地址:http://www.cnblogs.com/Murcielago/p/4202738.html