SWEA 1966 숫자를 정렬하자

1 개요[ | ]

SWEA 1966 숫자를 정렬하자

2 C++[ | ]

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int T, N;
int a[50];
int main() {
	scanf("%d", &T);
	for(int tc=1; tc<=T; tc++) {
		scanf("%d", &N);
		for(int i=0; i<N; i++) scanf("%d", &a[i]);
		sort(a, a+N);
		printf("#%d ", tc);
		for(int i=0; i<N; i++) printf("%d ", a[i]);
		printf("\n");
	}
}

3 Java[ | ]

import java.util.Scanner;
import java.util.Arrays;
public class Solution {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        for(int tc=1; tc<=T; tc++) {
            int i, n = sc.nextInt();
            int a[] = new int[n];
            for(i=0; i<n; i++) a[i] = sc.nextInt();
            Arrays.sort(a);
            System.out.format("#%d ", tc);
            for(i=0; i<n; i++) System.out.format("%d ", a[i]);
            System.out.println();
        }
    }
}
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}