티스토리 뷰
- 카드게임
#include <iostream>
/* 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 i, a[11], b[11], a_cnt=0, b_cnt=0, lw=0;
for(i=1; i<=10; i++){
scanf("%d", &a[i]);
}
for(i=1; i<=10; i++){
scanf("%d", &b[i]);
}
for(i=1; i<=10; i++){
if(a[i]==b[i]) {
a_cnt++;
b_cnt++;
}
else if(a[i] > b[i]) {
a_cnt+=3;
lw=1;
}
else {
b_cnt+=3;
lw=2;
}
}
printf("%d %d\n", a_cnt, b_cnt);
if(a_cnt == b_cnt) {
if(lw==1){
printf("A");
}else if(lw==2){
printf("B");
} else if(lw==0){
printf("D");
}
}
else if(a_cnt > b_cnt) printf("A");
else printf("B");
return 0;
}
- 온도의 최대값
#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, k, i, sum=0, max=-2147000000;
scanf("%d %d", &n, &k);
std::vector<int> a(n);
for(i=0; i<n; i++){
scanf("%d", &a[i]);
}
for(i=0; i<k; i++){
sum+=a[i];
}
for(i=k; i<n; i++){
sum=sum+(a[i]-a[i-k]);
if(max<sum) max=sum;
}
printf("%d", max);
return 0;
}
- 이중 for문을 사용해서도 풀 수 있는 문제이지만 for문을 하나만 사용해서 풀 수 있어야 함
- a배열의 i인덱스를 활용해서 a[i]값을 sum에 합하고 a[i-k]값을 sum에서 빼주면 다음 sum값이 도출됨
'algorithm' 카테고리의 다른 글
[c++] 석차 구하기 (0) | 2020.12.08 |
---|---|
[c++] 연속부분증가수열, Jolly jumpers (0) | 2020.12.07 |
[c++] 가위바위보 (0) | 2020.12.05 |
[c++] 층간소음 (0) | 2020.12.04 |
[c++] 아나그램, 선생님 퀴즈 (0) | 2020.12.03 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- react
- 재귀함수
- dfs
- 이진탐색
- server side rendering
- 인접리스트
- 교착상태
- client side rendering
- stackframe
- 클래스
- C++
- Stack
- 퀵정렬
- 동적프로그래밍
- 세마포어
- 입출력장치
- 스텍
- 알고리즘
- 자료구조
- C
- 병행프로세스
- Java
- 최단경로
- 소프트웨어
- BFS
- 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 |
글 보관함