PROBLEM LINK:
Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Author: Arjun Arul
Tester: Shubham Anand Jain
Editorialist: Nishank Suresh
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Given the rating R of a person, output which division he belongs to.
EXPLANATION:
Simply do exactly as the problem asks - input R, check which of the 3 ranges it lies in, and print the corresponding division. The simplest implementation of this is to use if-else statements.
TIME COMPLEXITY:
\mathcal{O}(1) per testcase.
SOLUTIONS:
Setter's Solution
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define rb pop_back
#define ti tuple<int, int, int>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define mp make_pair
#define mt make_tuple
using namespace std;
FILE *fp;
ofstream outfile;
long long readInt(long long l,long long r,char endd){
long long x=0;
int cnt=0;
int fi=-1;
bool is_neg=false;
while(true){
// char g=getchar();
char g = getc(fp);
if(g=='-'){
assert(fi==-1);
is_neg=true;
continue;
}
if('0'<=g && g<='9'){
x*=10;
x+=g-'0';
if(cnt==0){
fi=g-'0';
}
cnt++;
assert(fi!=0 || cnt==1);
assert(fi!=0 || is_neg==false);
assert(!(cnt>19 || ( cnt==19 && fi>1) ));
} else if(g==endd){
if(is_neg){
x= -x;
}
// cerr << x << " " << l << " " << r << endl;
assert(l<=x && x<=r);
return x;
} else {
assert(false);
}
}
}
string readString(int l,int r,char endd){
string ret="";
int cnt=0;
while(true){
// char g=getchar();
char g=getc(fp);
assert(g != -1);
if(g==endd){
break;
}
cnt++;
ret+=g;
}
assert(l<=cnt && cnt<=r);
return ret;
}
long long readIntSp(long long l,long long r){
return readInt(l,r,' ');
}
long long readIntLn(long long l,long long r){
return readInt(l,r,'\n');
}
string readStringLn(int l,int r){
return readString(l,r,'\n');
}
string readStringSp(int l,int r){
return readString(l,r,' ');
}
const int maxt = 1000, minr = 1000, maxr = 4500;
const string newln = "\n", space = " ";
int main()
{
int t, r; cin >> t;
while(t--){
cin >> r;
int ans = 1;
if(r < 1600)ans = 3;
else if(r < 2000)ans = 2;
cout << ans << endl;
}
}
Tester's Solution
//By TheOneYouWant
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
int main(){
fastio;
int tests;
cin >> tests;
while(tests--){
int r;
cin >> r;
if(r >= 2000){
cout << 1 << endl;
}
else if(r >= 1600){
cout << 2 << endl;
}
else{
cout << 3 << endl;
}
}
return 0;
}
Editorialist's Solution
for _ in range(int(input())):
rating = int(input())
if rating >= 2000:
print(1)
elif rating >= 1600:
print(2)
else:
print(3)