티스토리 뷰
- 석차 구하기
#include <iostream>
#include <vector>
/* 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;
scanf("%d", &n);
std::vector <int> a(n), b(n);
for(i=0; i<n; i++){
scanf("%d", &a[i]);
b[i]=1;
}
for(i=0; i<n; i++){
for(j=i+1; j<n; j++){
if(a[i] < a[j]) b[i]++;
else if(a[i] > a[j]) b[j]++;
}
}
for(i=0; i<n; i++){
printf("%d ", b[i]);
}
return 0;
}
- 마라톤
#include <iostream>
#include <vector>
#include <algorithm>
//내가 짠것
/* 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;
scanf("%d", &n);
std::vector <int> a(n), b(n);
for(i=0; i<n; i++){
scanf("%d", &a[i]);
b[i]=1;
}
for(i=n-1; i>=0; i--){
for(j=0; j<i; j++){
if(a[i] < a[j]) b[i]++;
}
}
for(i=0; i<n; i++){
printf("%d ", b[i]);
}
return 0;
}
// 참고한것
#include <iostream>
#include <vector>
#include <algorithm>
/* 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, cnt=1;
scanf("%d", &n);
std::vector <int> a(n);
for(i=0; i<n; i++){
scanf("%d", &a[i]);
}
printf("1 ");
for(i=1; i<n; i++){
cnt=1;
for(j=i-1; j>=0; j--){
if(a[i] < a[j]) cnt++;
}
printf("%d ", cnt);
}
return 0;
}
'algorithm' 카테고리의 다른 글
[c++] 3의 개수구하기(large) (0) | 2020.12.11 |
---|---|
[c++] N!의 표현법, N!에서 0의 개수 (0) | 2020.12.10 |
[c++] 연속부분증가수열, Jolly jumpers (0) | 2020.12.07 |
[c++] 카드게임, 온도의 최대값 (0) | 2020.12.06 |
[c++] 가위바위보 (0) | 2020.12.05 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 최단경로
- dfs
- 동적프로그래밍
- 이진탐색
- react
- 교착상태
- 인접리스트
- stackframe
- 구조체
- 퀵정렬
- 세마포어
- 알고리즘
- 병행프로세스
- 입출력장치
- 스텍
- 자료구조
- 소프트웨어
- Stack
- C
- 인접행렬
- BFS
- 운영체제
- C++
- 배열
- client side rendering
- 재귀함수
- Java
- 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 |
글 보관함