A. Olympic Ranking
The Olympic Games are the most important sporting events in human history. Usually, the Olympic Games are held every four years. However, the 2020 Olympic Games just finished in August 2021 due to the COVID-19 outbreaks.
There are more than 200 nations participating in the Olympic Games. Thousands of athletes around the world compete in various sports. The athletes represent their countries or National Olympic Committees (NOCs) to compete for medals. Therefore, each country or NOC may win medals in the competitions.
There are three types of medals: gold medals, silver medals, and bronze medals. Typically, the gold medals are awarded to the winners of the competitions, and silver medals are awarded to the runner-ups. Most of the bronze medals are awarded to the second runner-ups. However, there can be no second runner-up in some sports. The bronze medals can be awarded in different manners. For example, in a few tournament sports, such as wrestling, boxing, and judo, two bronze medals are awarded to the eliminated semi-finalists.
A country or NOC has a better rank than another country or NOC if one of the following conditions holds.
- It wins more gold medals.
- It wins the same amount of gold medals, and it wins more silver medals.
- It wins the same amount of gold medals and silver medals, and it wins more bronze medals.
Please write a program to find the country or NOC which has the best rank among all countries and NOCs.
Input
The first line of the input contains one positive integer n. Then n lines follow. Each of the following lines contains three non-negative integers g, s, b, and the name of a country or NOC. They are separated by blanks.
- 1≤n<300
- g,s,b∈{0,1,…,999}
- There is only one country or NOC of the best rank.
- The names of countries and NOCs consist of only printable ASCII characters.
- The size of an input file does not exceed 3 megabytes.
Output
Print the name of the country or NOC of the best rank.
Examples
Input
4 22 21 22 Great Britain 27 14 17 Japan 39 41 33 United States of America 20 28 23 ROC
Output
United States of America
Input
3 999 999 998 Malaysia 999 999 999 Thailand 999 998 999 Indonesia
Output
Thailand
题解:思路简单,主要是名字的处理。
#include<bits/stdc++.h>
using namespace std;
const int N=310;
struct point
{
int g,s,b;
string name;
}p[N];
string str;
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>p[i].g >>p[i].s >>p[i].b >>str;
p[i].name =str;
while(getchar()!='\n')
{
cin>>str;
p[i].name =p[i].name +" "+str;
}
}//名字的处理
int flag=0;
for(int i=1;i<n;i++)
{
if(p[flag].g >p[i].g )
{
continue;
}
else if(p[flag].g ==p[i].g )
{
if(p[flag].s >p[i].s )
{
continue;
}
else if(p[flag].s ==p[i].s )
{
if(p[flag].b >p[i].b )
{
continue;
}
else
{
flag=i;
}
}
else
{
flag=i;
}
}
else
{
flag=i;
}
}
cout<<p[flag].name <<endl;
return 0;
}
B. Aliquot Sum
A divisor of a positive integer n is an integer d where m=nd is an integer. In this problem, we define the aliquot sum s(n) of a positive integer n as the sum of all divisors of n other than n itself. For examples, s(12)=1+2+3+4+6=16, s(21)=1+3+7=11, and s(28)=1+2+4+7+14=28.
With the aliquot sum, we can classify positive integers into three types: abundant numbers, deficient numbers, and perfect numbers. The rules are as follows
1.A positive integer x is an abundant number if s(x)>x.
2.A positive intewer y is a deficient number if s(y)<y.
3.A positive integer z is a perfect number if s(z)=z.
You are given a list of positive integers. Please write a program to classify them.
Input
The first line of the input contains one positive integer T
indicating the number of test cases. The second line of the input contains T space-separated positive integers n1,…,nT.
1≤T≤10^6
1≤ni≤10^6 for i∈{1,2,…,T}
Output
Output T lines. If ni is an abundant number, then print abundant on the i-th line. If ni is a deficient number, then print deficient on the i-th line. If ni is a perfect number, then print perfect on the i-th line.
Example
Input
3 12 21 28
Output
abundant deficient perfect
题解:整数所有因子的处理。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
ll ans[1000005];
void init()
{
for(int i=1;i<1000005;i++)
{
for(int j=i*2;j<=1000005;j+=i)
{
ans[j]+=i;
}
}
}
int main()
{
init();
int _;
cin>>_;
while(_--)
{
cin>>n;
if(ans[n]>n)
{
cout<<"abundant"<<endl;
}
else if(ans[n]==n)
{
cout<<"perfect"<<endl;
}
else
{
cout<<"deficient"<<endl;
}
}
return 0;
}
J. JavaScript
JavaScript is one of the most important computer languages now. It is high-level and multi-paradigm. It supports functional and imperative programming styles. However, the ICPC World Finals does not offer JavaScript for problem solving.
JavaScript is considered as a weakly typed language. It sometimes implicitly converts values of one type into another type. For example, the minus operator (-) does not have any meaning on strings; it is defined to operate on numbers. When the minus operator is applied on two strings, JavaScript will convert the operands from strings into numbers and then apply the minus operation. That is why "2" + "2" - "2" evaluates to 20 in JavaScript. Moreover, JavaScript converts a string into NaN (Not-a-Number) if the string does not represent a number. If any operand of a minus operation is NaN, then the result of the operation must be NaN. For example, "a" + "2" is NaN.
Given two strings x and y, please write a program to compute the result of x - y in JavaScript.
Input
There is only one line containing two space-separated non-empty strings x and y.
- x and y consist of only English letters and digits.
- Both x and y have lengths less than 6.
- If x contains an English letter, then you may assume that JavaScript converts x into NaN.
- If y contains an English letter, then you may assume that JavaScript converts y into NaN.
- You may assume that the result is not a number if it is not an integer.
Output
Print the result of the minus operation (x - y) on one Line. If the result is an integer, please print it without the decimal point. If the result is not a number, please print NaN.
Examples
Input
22 2
Output
20
Input
a 2
Output
NaN
Input
12345 x1y2z
Output
NaN
题解:string转数字的加减。
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int get(string q)
{
int ans=0;
for(int i=0;i<q.length();i++)
{
ans=ans*10+q[i]-'0';
}
return ans;
}
bool judge(string s)
{
bool flag=0;
for(int i=0;i<s.length();i++)
{
if(!isdigit(s[i]))
{
flag=1;
break;
}
}
return flag;
}
int main()
{
cin>>s1>>s2;
bool f1=judge(s1);
bool f2=judge(s2);
if(f1==1||f2==1)
{
cout<<"NaN"<<endl;
}
else
{
//cout<<get(s1)<<" "<<get(s2)<<endl;
cout<<get(s1)-get(s2)<<endl;
}
return 0;
}