티스토리 뷰
- 삽입정렬
#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
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=1; i<n; i++){
tmp=a[i];
for(j=i-1; j>=0; j--){
if(a[j]>tmp) a[j+1]=a[j];
else {
break;
}
}
a[j+1]=tmp;
}
for(i=0; i<n; i++){
printf("%d ", a[i]);
}
return 0;
}
- Special sort
#include<stdio.h>
int main() {
freopen("input.txt", "rt", stdin);
int a[101], n, tmp, min, i, j;
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%d", &a[i]);
}
for(i=0; i<n-1; i++){
for(j=0; j<n-i-1; j++){
if(a[j]>0 && a[j+1]<0){
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++] 두배열합치기 (0) | 2020.12.23 |
---|---|
[c++] Least Recently Used, Inversion Sequence (0) | 2020.12.22 |
[c++] 3등의 성적은, 버블정렬 (0) | 2020.12.14 |
[c++] 탄화수소 질량, 선택정렬 (0) | 2020.12.13 |
[c++] 3의 개수구하기(large) (0) | 2020.12.11 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- server side rendering
- 클래스
- 소프트웨어
- 입출력장치
- react
- 병행프로세스
- stackframe
- 알고리즘
- BFS
- 스텍
- client side rendering
- 최단경로
- 동적프로그래밍
- 인접행렬
- 퀵정렬
- 배열
- javascript
- 인접리스트
- 교착상태
- dfs
- C
- 세마포어
- 구조체
- Java
- 자료구조
- 운영체제
- 재귀함수
- C++
- 이진탐색
- Stack
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 29 | 30 | 31 |
글 보관함