문제 링크입니다: www.acmicpc.net/problem/5102
5102번: Sarah's Toys
Input will be a number of lines, with each line representing a night in Sarah’s house. Each line will have 2 whole numbers, separated by a space. The first number is how many stuffed toys she owns at the time. The second number is the number of toys left
www.acmicpc.net
간단한 구현 문제였습니다.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
while (true) | |
{ | |
int a, b; | |
cin >> a >> b; | |
if (a == 0 && b == 0) | |
{ | |
break; | |
} | |
int groupNum = max((a - b) / 2 - (a - b) % 2, 0); | |
int groupOfThree = a - b <= 1 ? 0 : (a - b) % 2; | |
cout << groupNum << " " << groupOfThree << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 19944번 뉴비의 기준은 뭘까? (3) | 2021.03.29 |
---|---|
백준 5103번 DVDs (0) | 2021.03.28 |
백준 19698번 헛간 청약 (0) | 2021.03.27 |
백준 19602번 Dog Treats (0) | 2021.03.27 |
백준 18414번 X に最も近い値 (0) | 2021.03.27 |