字符串排序(2)
字符串排序(2)
http://www.nowcoder.com/questionTerminal/a2ec8633ff3a42a185a74bff79c90cc9
#include<iostream> #include<string.h> #include<vector> using namespace std; int main(){ char* str = new char[20]; while(cin>>str){ vector<char*>strs; while(true){ for(vector<char*>::iterator i = strs.begin();;i++) { if(i==strs.end()){ strs.push_back(str); break; } if(strcmp(*i,str)>0){ strs.insert(i,str); break; } } if(cin.get() == '\n'){ for(vector<char*>::iterator i = strs.begin();i != strs.end();i++) cout<<*i<<" "; break; } str = new char[20]; cin>>str; } cout<<endl; } }