티스토리 뷰
- Least Recently Used
#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 s, n, i, j, pos;
int c[10], a[1000];
scanf("%d", &s);
scanf("%d", &n);
for(i=0; i<n; i++){
scanf("%d", &a[i]);
}
for(i=0; i<n; i++){
pos = -1;
for(j=0; j<s; j++){
if(a[i]==c[j]) pos = j;
}
if(pos==-1){
for(j=s-1; j>=0; j--){
c[j+1]=c[j];
}
} else {
for(j=pos-1; j>=0; j--){
c[j+1]=c[j];
}
}
c[0]=a[i];
}
for(i=0; i<s; i++){
printf("%d ", c[i]);
}
return 0;
}
- Inversion Sequence
#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;
int a[100], b[100];
scanf("%d", &n);
for(i=1; i<=n; i++){
scanf("%d", &a[i]);
}
for(i=n; i>=1; i--){
for(j=1; j<=a[i]; j++){
b[i+j-1]=b[i+j];
}
b[i+j-1] = i;
}
for(i=1; i<=n; i++){
printf("%d ", b[i]);
}
return 0;
}
'algorithm' 카테고리의 다른 글
[c++] 교집합, 연속된 자연수 (0) | 2020.12.24 |
---|---|
[c++] 두배열합치기 (0) | 2020.12.23 |
[c++] 삽입정렬, Special sort (0) | 2020.12.15 |
[c++] 3등의 성적은, 버블정렬 (0) | 2020.12.14 |
[c++] 탄화수소 질량, 선택정렬 (0) | 2020.12.13 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- C
- 클래스
- stackframe
- dfs
- 세마포어
- react
- 알고리즘
- 병행프로세스
- 퀵정렬
- 인접리스트
- 배열
- javascript
- 이진탐색
- 스텍
- 교착상태
- 최단경로
- 동적프로그래밍
- 구조체
- 인접행렬
- BFS
- 운영체제
- 재귀함수
- Stack
- C++
- 입출력장치
- server side rendering
- client side rendering
- Java
- 소프트웨어
- 자료구조
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함