公式

A - Piling Up 解説 by en_translator


Denoting by \(R\) the current rating, the increase in rating required to have more ^ is

  • \((100-R)\) if \(1\leq R\leq 99\);
  • \((200-R)\) if \(100\leq R\leq 199\);
  • \((300-R)\) if \(200\leq R\leq 299\).

This value is to be printed, which can be implemented with an if statement. Thus, the problem has been solved.

Also, noticing ^ increases at every multiple of \(100\), one can utilize the remainder when \(R\) is divided by \(100\) to implement it without using a conditional branch.

Sample code in C++:

#include <bits/stdc++.h>
using namespace std;

int main(void){
	int r;	
	cin >> r;

	if(r<100)cout << (100-r) << endl;
	else if(r<200)cout << (200-r) << endl;
	else cout << (300-r) << endl;

	return 0;
}

Sample code in Python:

r=int(input())
if r<100:
    print(100-r)
elif r<200:
    print(200-r)
else:
    print(300-r)

Sample code in C++ (another solution):

#include <bits/stdc++.h>
using namespace std;

int main(void){
	int r;	
	cin >> r;

	cout << 100-(r%100) << endl;

	return 0;
}

投稿日時:
最終更新: