文章
6
粉丝
0
获赞
38
访问
4.4k
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
cin.ignore();
vector<string>countries(n);
for (int i = 0; i < n; i++) {
getline(cin, countries[i]); //getline可以读取一整行字符串(包括空格)直到换行
}
sort(countries.begin(), countries.end());//sort默认对String型按字典序排列
for (int i = 0; i < countries.size(); i++) {
string country = countries[i]; // 每次拷贝一个字符串
cout << country << endl;
}
/*
for (const string& country : countries) {
cout << country << endl;
}
*/
return 0;
}
第一次使用容器,当作可以动态增大的数组即可,注释中的是另一种输出的方法,和上面的for循环等价
登录后发布评论
暂无评论,来抢沙发