티스토리 뷰

  • 3등의 성적은
#include<stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
	//freopen("input.txt", "rt", stdin);	
	int n, i, j, tmp, cnt=1;
	int a[101]; 
	scanf("%d", &n);
	
	for(i=0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for(i=0; i < n; i++){
		for(j=i+1; j < n; j++){
			if(a[i]<a[j]) {
				tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	
	i=0;
	while(cnt<3){
		if(a[i]>a[i+1]){
			cnt++;
		}
		i++;
	}
	printf("%d ", a[i]);		
	return 0;
}

 

  • 버블정렬
#include<stdio.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main() {
	//freopen("input.txt", "rt", stdin);	
	int n, i, j, tmp;
	int a[101]; 
	scanf("%d", &n);
	
	for(i=0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for(i=0; i < n; i++){
		for(j=0; j < n-i-1; j++){
			if(a[j]>a[j+1]) {
				tmp = a[j];
				a[j] = a[j+1];
				a[j+1] = tmp;
			}
		}
	}
	
	for(i=0; i<n; i++){
		printf("%d ", a[i]);
	}
	return 0;
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함