문제 링크입니다: https://www.acmicpc.net/problem/9437
9437번: 사라진 페이지 찾기
각 테스트 케이스에 대해 두가지 정수 N,P가 주어진다. 4의 배수인 N(4 ≤ N ≤ 1000)은 탐구영역의 전체 페이지 수이며, P(1 ≤ P ≤ N)는 선택된 한 페이지다. 입력의 마지막은 하나의 0만 주어진다.
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 <vector> | |
#include <algorithm> | |
using namespace std; | |
const int MAX = 3; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
while (1) | |
{ | |
int N; | |
cin >> N; | |
if (N == 0) | |
{ | |
break; | |
} | |
int P; | |
cin >> P; | |
vector<int> pages; | |
pages.push_back(P % 2 ? P + 1 : P - 1); | |
pages.push_back(P % 2 ? N - P : N - P + 1); | |
pages.push_back(P % 2 ? N - P + 1 : N - P + 2); | |
sort(pages.begin(), pages.end()); | |
for (int page : pages) | |
{ | |
cout << page << " "; | |
} | |
cout << "\n"; | |
} | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 9469번 폰 노이만 (0) | 2021.07.19 |
---|---|
백준 9449번 Garage (1) | 2021.07.18 |
백준 9366번 삼각형 분류 (0) | 2021.07.12 |
백준 9325번 얼마? (0) | 2021.07.11 |
백준 9317번 Monitor DPI (2) | 2021.07.07 |