1. 程式人生 > 實用技巧 >AtCoder Beginner Contest 173 A - Payment

AtCoder Beginner Contest 173 A - Payment

A - Payment


Time Limit: 2 sec / Memory Limit: 1024 MB

Score :100100points

Problem Statement

We will buy a product forNNyen (the currency of Japan) at a shop.

If we use only10001000-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
  • NNis 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 1Copy

Copy
1900

Sample Output 1Copy

Copy
100

We will use two1000-yen bills to pay the price and receive100yen in change.


Sample Input 2Copy

Copy
3000

Sample Output 2Copy

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
; }