Kattis-99 Problems
Posted 做一个AC梦
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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.
代码
#include<iostream>
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<<endl;
结束语
好兄弟好兄弟,留下你的关注和点赞,666走一波!!!!!
以上是关于Kattis-99 Problems的主要内容,如果未能解决你的问题,请参考以下文章