문제 링크입니다: https://www.acmicpc.net/problem/5101
5101번: Sequences
11 is the 5th term The sequence is –1, -4, -7, -10 (-1+ -3 = -4, -4 + –3 = -7, -7+ -3 = -10) -8 isn’t in the sequence.
www.acmicpc.net
예외처리를 고려해야하는 구현 문제였습니다.
This file contains hidden or 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> | |
using namespace std; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
while (1) | |
{ | |
int a, b, c; | |
cin >> a >> b >> c; | |
if (a == 0 && b == 0 && c == 0) | |
{ | |
break; | |
} | |
if ((b > 0 && c <= a) || (b < 0 && c >= a)) | |
{ | |
cout << "X\n"; | |
continue; | |
} | |
if ((c - a) % b == 0) | |
{ | |
cout << (c - a) / b + 1 << "\n"; | |
continue; | |
} | |
cout << "X\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 5217번 쌍의 합 (0) | 2021.05.19 |
---|---|
백준 5205번 School Colors (0) | 2021.05.19 |
백준 5086번 배수와 약수 (0) | 2021.05.19 |
백준 5074번 When Do We Finish? (0) | 2021.05.18 |
백준 5073번 삼각형과 세 변 (0) | 2021.05.18 |