#字符串排序#__huawei_no.14-1
字符串排序
https://www.nowcoder.com/practice/5af18ba2eb45443aa91a11e848aa6723
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin>>n;
string s;
vector<string>q;
for(int i = 0; i < n; i++){
cin>>s;
q.push_back(s);
}
for(int i = 0; i < n; i++){
for(int j = 1 ; j < n ; j++){
if(q[j] < q[j-1]){
swap(q[j],q[j-1]);
}
}
}
for(int i = 0; i<n ; i++){
cout<<q[i]<<endl;
}
return 0;
}
// 64 位输出请用 printf("%lld")
解法有点bug,暴力的将两个进行比对,如果两个字符串大小并不是一样大小,那么这个比较明显就多余了,转了空子。只能说是一个土方法。
查看3道真题和解析