※ 글쓴이는 취미로 코딩을 익혀보는 사람이라 정확하지 않은 내용을 담고 있을 수 있다 ※
이번에 볼 문제는 백준 15179번 문제인 Golf Croquet이다.
문제는 아래 링크를 확인하자.
https://www.acmicpc.net/problem/15179
15179번: Golf Croquet
The input represents part or all of a single game of golf croquet. The first two lines each contain the name of a team, each consisting of one or more words. The name will be no more than 30 characters long. The first named team play blue and black. The th
www.acmicpc.net
문제에 주어진 내용을 그대로 잘 구현해주자.
팀 이름을 입력받을 때는 줄단위로 입력을 받아야 함에 유의하자.
또한, 팀의 점수가 6점일 때 D가 발생해 점수가 추가되는 경우 8점이 아닌 7점으로 기록해야 함에 유의하자.
아래는 제출한 소스코드이다.
#include <iostream>
#include <string>
using namespace std;
int score1, score2;
string team1, team2;
string s; int slen;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
getline(cin, team1);
getline(cin, team2);
cin >> slen >> s;
for (int i = 0; i < slen; i++) {
if (i & 1) {
if (s[i] == 'H') score2++;
else if (s[i] == 'D') score2 += 2;
else if (s[i] == 'O') score1++;
}
else {
if (s[i] == 'H') score1++;
else if (s[i] == 'D') score1 += 2;
else if (s[i] == 'O') score2++;
}
if (score1 > 6) {
score1 = 7;
cout << team1 << ' ' << score1 << ' ' << team2 << ' ' << score2 << '.' << ' ' << team1 << " has won.";
return 0;
}
else if (score2 > 6) {
score2 = 7;
cout << team1 << ' ' << score1 << ' ' << team2 << ' ' << score2 << '.' << ' ' << team2 << " has won.";
return 0;
}
}
if (score1 > score2) cout << team1 << ' ' << score1 << ' ' << team2 << ' ' << score2 << '.' << ' ' << team1 << " is winning.";
else if (score1 < score2) cout << team1 << ' ' << score1 << ' ' << team2 << ' ' << score2 << '.' << ' ' << team2 << " is winning.";
else cout << team1 << ' ' << score1 << ' ' << team2 << ' ' << score2 << '.' << ' ' << "All square.";
}
728x90
'BOJ' 카테고리의 다른 글
[BOJ 5342 // C++] Billing (0) | 2022.12.22 |
---|---|
[BOJ 5360 // C++] Next Permutation (0) | 2022.12.22 |
[BOJ 5292 // C++] Counting Swann's Coins (0) | 2022.12.22 |
[BOJ 10190 // C++] Acronyms (0) | 2022.12.22 |
[BOJ 6843 // C++] Anagram Checker (0) | 2022.12.22 |