728x90
반응형
% 100
- 제목
99 Problems
- 조건
시간 제한 : 1 초
메모리 제한 : 1024 MB
- 문제
Ingrid is the founder of a company that sells bicycle parts. She used to set the prices of products quite arbitrarily, but now she has decided that it would be more profitable if the prices end in $99$.
You are given a positive integer $N$, the price of a product. Your task is to find the nearest positive integer to $N$ which ends in $99$. If there are two such numbers that are equally close, find the bigger one.
- 입력
The input contains one integer $N$ (1 ≤ N ≤ 10^4), the price of a product. It is guaranteed that the number N does not end in 99.
- 출력
Print one integer, the closest positive integer that ends in 99. In case of a tie, print the bigger one.
예제 입력1 | 예제 출력1 |
10 | 99 |
예제 입력1 | 예제 출력1 |
249 | 299 |
예제 입력1 | 예제 출력1 |
10000 | 9999 |
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
#define endl '\n'
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
bool is99(int x){
if(x % 100 == 99) return true;
return false;
}
int main() {
fastio;
int N;
cin >> N;
if(1 <= N && N <= 98){
cout << 99 << endl;
return 0;
}
int idx = 1;
while(true){
if(is99(N + idx)){
cout << N + idx << endl;
break;
}
if(is99(N - idx)){
cout << N - idx << endl;
break;
}
idx++;
}
return 0;
}
728x90
반응형
'Problem Solving > BaekJoon' 카테고리의 다른 글
[BOJ/백준] 9655 - 돌 게임 (0) | 2022.09.06 |
---|---|
[BOJ/백준] 16562 - 친구비 (0) | 2022.09.04 |
[BOJ/백준] 25527 - Counting Peaks of Infection (0) | 2022.09.03 |
[BOJ/백준] 25311 - UCPC에서 가장 쉬운 문제 번호는? (0) | 2022.09.02 |
[BOJ/백준] 17298 - 오큰수 (0) | 2022.09.02 |