文章

1

粉丝

52

获赞

0

访问

77

头像
字符串的字典排序 题解:
P5204 西北农林科技大学机试题
发布于2025年4月16日 11:54
阅读数 77

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    vector<string> strs(5);  // 创建存储5个字符串的容器
    for (int i = 0; i < 5; ++i) {
        getline(cin, strs[i]);  // 正确读取可能包含空格的字符串
    }
    
    sort(strs.begin(), strs.end());  // 默认字典序排序
    
    for (const auto& s : strs) {
        cout << s << endl;  // 按行输出排序结果
    }
    return 0;
}

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发