Official

A - 10yen Stamp Editorial by en_translator


If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from practice contest. There you can find a sample code for each language.
Also, if you are not familiar to problems in programming contests, we recommend you to try some problems in “AtCoder Beginners Selection” (https://atcoder.jp/contests/abs).
「競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) (https://atcoder.jp/contests/typical90) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.


The following two processes are required to solve this problem.

  • Find how many yens is \(X\) yen less than \(Y\) yen. This can be found as \(Y - X\).
    • Note that, if \(X \ge Y\), then the answer is determined to be \(0\), so output \(0\) and exit the program.
  • Find how many \(10\)-yen stamps are required to pay (at least) \(Y-X\) yen. In order to find this, we have to divide \(Y-X\) by \(10\), rounding up the fractional part.

There are various ways to round up numbers depending on programming languages, among which the following way is the most generic.

The quotient when dividing a positive integer \(a\) by another positive integer \(b\), with the fractional part rounded up, is equal to the quotient when dividing \((a+b-1)\) by \(b\), with the fractional part rounded down.
The advantage of this method: In many languages, the result of a division of an integer by another integer is rounded down. That is why this method simplifies the implementation. Note: this does not work if \(a\) or \(b\) is a real number.

Sample Code (C++):

#include<bits/stdc++.h>

using namespace std;

int ceil(int a,int b){return (a+b-1)/b;}

int main(){
  int x,y;
  cin >> x >> y;
  if(x>=y){cout << "0\n";return 0;}
  cout << ceil(y-x,10) << '\n';
  return 0;
}

posted:
last update: