2021 ICPC Asia Taiwan Online Programming Contest ABJ

A. Olympic Ranking

题意

n个国家,给出国家的名字和获得的金银铜牌数。要求输出rank1的国家名字。排名规则:先选金牌多的,如果都相等就选银牌多的,否则选铜牌多的。

思路与代码

很简单的一个结构体排序,需要注意的是国家名称的读入具有一定技巧。

#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 2000007;
const int INF = 0x3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1); 
inline ll read(){
	ll x = 0, f = 1; char ch; ch = getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n;
string s;
struct node{
    int au,ag,cu;
    string name;
}q[305];
int cmp(node a,node b)
{
    if(a.au!=b.au)
        return a.au>b.au;
    else
    {
        if(b.ag!=a.ag)
         return a.ag>b.ag;
        else
            return a.cu>b.cu;
    }
}
void solve() 
{
    n=read();
    for(int i=1;i<=n;i++)
    {
        q[i].au=read(),q[i].ag=read(),q[i].cu=read();
        cin>>s;
        q[i].name=s;
        while(getchar()!='\n')
        {
            cin>>s;
         //   if(q[i].name.size()==0)
             //   q[i].name=s;
           // else 
           q[i].name=q[i].name+" "+s;
        }
   //     cout<<Endl<<"q[i].name="<<q[i].name<<Endl;
    }
    sort(q+1,q+1+n,cmp);
    cout<<q[1].name<<Endl;
}
 
int main() {
//for(int T = read(); T; T--)
		solve();
	return 0;
} 

B. Aliquot Sum

题意

s(n)=所有除了n以外的的除数之和。比较s(n)与n并按要求输出。

思路和代码

预处理出s(n)即可。

#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 2000007;
const int INF = 0x3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1); 
inline ll read(){
	ll x = 0, f = 1; char ch; ch = getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
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;
    }
}
void solve() 
{
    n=read();
    if(ans[n]>n)
    {
        cout<<"abundant"<<Endl;
    }
    else if(ans[n]<n)
    {
        cout<<"deficient"<<Endl;
    }
    else cout<<"perfect"<<Endl;
}
 
int main() {
    init();
for(int T = read(); T; T--)
		solve();
	return 0;
} 

J. JavaScript

题意

给出string x和y,如果x和y中含有英文字母输出NaN,否则输入x-y的值。

代码与思路

扫描x和y,发现有不是数字的就break掉输出NaN即可。

#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define Endl "\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 2000007;
const int INF = 0x3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1); 
inline ll read(){
	ll x = 0, f = 1; char ch; ch = getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
string x,y;
bool flag;
int get(string q){
	int ans=0;
    for(int i=0;i<q.length();i++)
        ans=ans*10+q[i]-'0';
	return ans;
}
void solve() 
{
    flag=1;
    cin>>x>>y;
    for(int i=0;i<x.length();i++)
        if(!isdigit(x[i]))
        {
            flag=0;
            break;
        }
    for(int i=0;i<y.length();i++)
        if(!isdigit(y[i]))
        {
            flag=0;
            break;
        }
    if(!flag)
    {
        cout<<"NaN"<<Endl;
    }
    else
    {
        cout<<get(x)-get(y)<<Endl;;
    }
}
 
int main() {
//	for(int T = read(); T; T--)
		solve();
	return 0;
} 
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值