일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- programmers
- Bronze
- level1
- stack
- knapsack Problem
- effective C++
- PrefixSum
- trie
- algorithm
- solid 원칙
- SWEA
- Modern C++
- Euclidean
- BOJ
- BFS
- LEVEL2
- dirtyflag pattern
- Project
- 8-Puzzle
- 프로그래머스
- Silver
- Zenject
- Gold
- two pointer
- Flyweight Pattern
- level3
- binary search
- 프로세스 상태
- 3D RPG
- Unity
Archives
- Today
- Total
Patrick's Devlog
[BOJ/C++] 카드게임(10801번) 본문
1. 개요
https://www.acmicpc.net/problem/10801
10801번: 카드게임
두 사람 A와 B는 1부터 10까지의 숫자가 하나씩 적힌 열 장의 카드로 ‘게임’을 한다. 게임은 총 열 번의 ‘라운드’로 구성되고, 각 라운드 마다 자신이 가지고 있는 카드 중 하나를 제시하고,
www.acmicpc.net
1-1. 설명
두 사람 A, B는 1부터 10까지 숫자가 하나씩 적힌 열장 카드로 게임을 한다. 게임의 규칙은 위의 링크에서 확인이 가능하다. A와 B가 각 라운드마다 제시한 숫자와 각 라운드의 승자를 계산하여, 누가 이겼는지 출력하는 프로그램을 작성한다.
1-2. 제한 사항
- 첫줄에는 A가 제시한 카드 숫자 10개가 라운드 순서대로 주어짐
- 둘째줄에는 B가 제시한 카드 숫자 10개가 라운드 순서대로 주어짐
2. 구현
2-1. 풀이
각각의 A, B가 제시한 카드를 배열에 저장하고 for문을 통해 비교해주었다.
2-2. 코드
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int A[10], B[10];
int countA = 0, countB = 0;
void split(string s, char delimiter, int flag) {
stringstream ss(s);
string str;
if (flag == 1) {
while (getline(ss, str, delimiter)) {
A[countA++] = stoi(str);
}
countA = 0;
}
else if (flag == 2) {
while (getline(ss, str, delimiter)) {
B[countB++] = stoi(str);
}
countB = 0;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string strA, strB;
getline(cin, strA);
getline(cin, strB);
split(strA, ' ', 1);
split(strB, ' ', 2);
for (int i = 0; i < 10; i++) {
if (A[i] > B[i]) countA += 1;
else if (A[i] < B[i]) countB += 1;
}
if (countA > countB) cout << 'A';
else if (countA < countB) cout << 'B';
else cout << 'D';
return 0;
}
'Algorithm > Algorithms Practice' 카테고리의 다른 글
[BOJ/C++] ROT13(11655번) (0) | 2022.10.18 |
---|---|
[BOJ/C++] 그룹 단어 체커(1316번) (0) | 2022.10.17 |
[BOJ/C++] 덩치(7568번) (0) | 2022.10.13 |
[BOJ/C++] 블로그(21921번) (0) | 2022.10.12 |
[프로그래머스/C++] 숫자 문자열과 영단어 (0) | 2022.10.11 |