链接:https://ac.nowcoder.com/acm/contest/5657/H
来源:牛客网

时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld
题目描述
对输入的字符串进行排序后输出
打开以下链接可以查看正确的代码
https://ac.nowcoder.com/acm/contest/5657#question

输入描述:
输入有两行,第一行n

第二行是n个空格隔开的字符串
输出描述:
输出一行排序后的字符串,空格隔开,无结尾空格
示例1
输入
复制
5
c d a bb e
输出
复制
a bb c d e

思路和心得

1.python3 [x for x in input().split()]

n = int(input())
words = [x for x in input().split()]
words.sort()
for word in words:
    print(word, end = ' ')
print()

2.c++ cin>>

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n; cin >> n;
    vector<string> words;
    string word;
    while(n --)
    {
        cin >> word;
        words.push_back(word);
    }
    sort(words.begin(), words.end());
    for (string word : words)
        cout << word << ' ';
    cout << endl;
    return 0;
}

3.java scan.nextInt() scan.next() scan.nextLine() Integer.parseInt()

import java.util.* ;

public class Main
{
    public static void main(String [] args)
    {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        String [] words = new String [n];
        for (int i = 0; i < n; i ++)
            words[i] = scan.next();

        Arrays.sort(words);
        for (int i = 0; i < n; i ++)
            System.out.print(words[i] + " ");
        System.out.println();

    }
}
import java.util.* ;

public class Main
{
    public static void main(String [] args)
    {
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        String [] words = scan.nextLine().split(" ");

        Arrays.sort(words);
        for (int i = 0; i < n; i ++)
            System.out.print(words[i] + " ");
        System.out.println();

    }
}