AtCoder Beginner Contest 173 A - Payment

A - Payment


Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 100100 points

Problem Statement

We will buy a product for NN yen (the currency of Japan) at a shop.

If we use only 10001000-yen bills to pay the price, how much change will we receive?

Assume we use the minimum number of bills required.

Constraints

  • 1N100001≤N≤10000
  • NN is an integer.

Input

Input is given from Standard Input in the following format:

NN

Output

Print the amount of change as an integer.


Sample Input 1 Copy

Copy
1900

Sample Output 1 Copy

Copy
100

We will use two 1000-yen bills to pay the price and receive 100 yen in change.


Sample Input 2 Copy

Copy
3000

Sample Output 2 Copy

Copy
0

We can pay the exact price.

题意:给你一个数,算出找零的数(其实原文更容易看懂)

解题思路:对n用1k求余如果余数为0则不用找钱(给的钱刚好为1k的整数倍),否则就要找1k-n%1k的零钱

代码如下:

#include<cstdio>
int main(void)
{
    int n;
    while(~scanf("%d",&n))
    printf("%d\n",n%1000==0?0:1000-n%1000);
    return 0;
}

 

posted @ 2020-07-12 20:47  MangataTS  阅读(274)  评论(0编辑  收藏  举报