728x90
반응형
문제 : https://www.acmicpc.net/problem/2751
문제
N개의 수가 주어졌을 때, 이를 오름차순으로 정렬하는 프로그램을 작성하시오.
입력
첫째 줄에 수의 개수 N(1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄부터 N개의 줄에는 숫자가 주어진다. 이 수는 절댓값이 1,000,000보다 작거나 같은 정수이다. 수는 중복되지 않는다.
출력
첫째 줄부터 N개의 줄에 오름차순으로 정렬한 결과를 한 줄에 하나씩 출력한다.
예제 입력 1
5
5
4
3
2
1
예제 출력 1
1
2
3
4
5
코드 :
# include <stdio.h>
# include <stdlib.h>
int al(const int *a,const int *b)
{
if(*(int*)a > *(int*)b)
return 1;
else if(*(int*)a < *(int*)b)
return -1;
else
return 0;
}
int main()
{
int n,i;
scanf("%d",&n);
int *arr = (int*)malloc(sizeof(int)*n);
for(i = 0; i<n; i++)
{
scanf("%d",&arr[i]);
}
qsort(arr,n,sizeof(int),al);
for(i = 0; i<n; i++)
{
printf("%d\n",arr[i]);
}
return 0;
}
728x90
반응형
최근댓글