以下是用C++实现的代码:

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

int main() {
    int n;
    std::cin >> n;
    
    std::vector<std::string> countries(n);
    for (int i = 0; i < n; i++) {
        std::cin >> countries[i];
    }
    
    std::sort(countries.begin(), countries.end());
    
    for (int i = 0; i < n; i++) {
        std::cout << countries[i] << std::endl;
    }
    
    return 0;
}

这段代码首先读取国家的个数n,然后使用一个vector来存储n个国家的名字。接下来使用一个循环来读取每个国家的名字,并将其存储到vector中。然后使用sort函数对vector进行排序,按照字母的顺序排序。最后使用循环输出排序后的国名

c++代码用二维字符数组完成 对给定的n1=n=20个国家名。国家名字长度不超过20。按其字母的顺序输出。输入第一行为国家的个数。以下n行为国家的名字。输出行排序后的国名输入样例 3 KoreaChina Japan输出样例China KoreaJapan

原文地址: https://www.cveoy.top/t/topic/hZ2q 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录