/**
输入一组英文单词,按词典顺序排序,不区分大小写
这个题目我依旧使用了最熟悉的sort函数和vector库!真的很好用~用过都说好、~
新使用了一个string大小小转换函数 transform(a.begin(),a.end(),a.begin(),towlower);
如果把towlower改成toupper就是变成大写字母啦~
在sort中使用transform函数 ,不区分大小写的题目要求,
**/
#include<iostream>
#include<string.h>
#include<algorithm>
#include<vector>
using namespace std;
bool cmp(string a,string b){
transform(a.begin(),a.end(),a.begin(),towlower);
transform(b.begin(),b.end(),b.begin(),towlower);
if(a>b) return 0;
else if(a<b) return 1;
else{
if(a.length()>=b.length()) return 0;
else return 1;
}
}
void show(vector<string> A){
cout<<"单词序列"<<endl;
for(int i=0;i<A.size();i++){
cout<<A[i]<<" ";
}
cout<<endl;
}
int main(){
vector<string> Word;
string w;
cin>>w;
while(w!="##"){
Word.push_back(w);
// cout<<w;
cin>>w;
}
cout<<endl;
//show(Word);
sort(Word.begin(),Word.end(),cmp);
show(Word);
return 0;
}