题解 | #求长方体表面积#
字符串排序
http://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
#include<bits/stdc++.h>
using namespace std;
//按照字典序排序,string直接比大小,可以用multiset直接输出
int main(){
string strInput="ssr";
int num = 0;
cin>>num;
vector<string> myVec;//不能初始化为{""},导致第一个元素存在且为空
// while(getline(cin, strInput)){//为什么第一个是空字符串?第一个已经用过了,所以为空了?
// myVec.push_back(strInput);
// }
for(int i = 0; i<num; ++i){
cin>>strInput;
myVec.push_back(strInput);
}
for(int i = 0; i<num; ++i){
for(int j = 0; j<num-i-1; ++j){
if (myVec[j]>myVec[j+1]) swap(myVec[j], myVec[j+1]);
}
}
for(auto str:myVec){
cout<<str<<endl;
}
return 0;
}