티스토리 뷰
- 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;
}
'algorithm' 카테고리의 다른 글
[c++] Least Recently Used, Inversion Sequence (0) | 2020.12.22 |
---|---|
[c++] 삽입정렬, Special sort (0) | 2020.12.15 |
[c++] 탄화수소 질량, 선택정렬 (0) | 2020.12.13 |
[c++] 3의 개수구하기(large) (0) | 2020.12.11 |
[c++] N!의 표현법, N!에서 0의 개수 (0) | 2020.12.10 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- BFS
- 소프트웨어
- dfs
- 퀵정렬
- client side rendering
- 스텍
- 이진탐색
- react
- 최단경로
- 자료구조
- 세마포어
- Stack
- 병행프로세스
- 재귀함수
- stackframe
- C++
- 동적프로그래밍
- Java
- C
- 운영체제
- server side rendering
- 입출력장치
- 인접행렬
- 클래스
- 알고리즘
- javascript
- 구조체
- 교착상태
- 배열
- 인접리스트
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함