Kattis-99 Problems

题目所述基本内容

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.

输入输出样例

Input

The input contains one integer N (1≤N≤104), the price of a product. It is guaranteed that the number N does not end in 99.

Output

Print one integer, the closest positive integer that ends in 99. In case of a tie, print the bigger one.

Kattis-99 Problems_第1张图片

 代码

#include
using namespace std;

int main() {
	int n;
	cin >> n;
	int price = 0;
	int a = 0;
	int m = 0;
    for(int i=99;i<=9999;i=i+100){
		a = n - i;
		if (a < 0) {
			a = i - n;
		}
		if (a < 100) {
			m = i + 100 - n;
			if (m < 0) {
				m = n - i - 100;
			}
			if (a < m) {
				price = i;
			}
			else {
				price = i + 100;
			}
			break;
		}
	}
	cout << price<

结束语

好兄弟好兄弟,留下你的关注和点赞,666走一波!!!!!

你可能感兴趣的:(c++,算法)