【PTA-训练day9】L2-021 点赞狂魔 + L1-034 点赞

L2-021 点赞狂魔 - 自定义排序 + 结构体 + set

PTA | 程序设计类实验辅助教学平台

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

typedef struct
{
    string name;
    int num; //博文出现次数k
    int fact; //实际上博文种类数
}stu;

bool cmp(stu a,stu b)
{
    if(a.fact==b.fact) return a.num<b.num;
    return a.fact>b.fact;
}

int main()
{
    stu p[101];
    set<int> st;
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        p[i].name=s;
        int k;
        cin>>k;
        p[i].num=k;
        for(int i=0;i<k;i++) 
        {
            int x;
            cin>>x;
            st.insert(x);
        }
        p[i].fact=st.size();
        st.clear();
    }
    sort(p,p+n,cmp);
    for(int i=0;i<3;i++)
    {
        if(i!=0) cout<<" ";
        if(i>n-1) cout<<'-';
        else cout<<p[i].name;
    }
}

 

L1-034 点赞 - 20

PTA | 程序设计类实验辅助教学平台

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

bool cmp(const pair<int,int>&a,const pair<int,int>&b)
{
    if(a.second!=b.second) return a.second>b.second;
    return a.first>b.first;
}

int main()
{
    int n;
    cin>>n;
    map<int,int>mp;
    while(n--)
    {
        int k;
        cin>>k;
        for(int i=0;i<k;i++)
        {
            int x;
            cin>>x;
            mp[x]++;
        }
    }
    vector<pair<int,int>> v(mp.begin(),mp.end());
    sort(v.begin(),v.end(),cmp);
    cout<<v[0].first<<' '<<v[0].second;
}

L1-033 出生年 - 15

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

int main()
{
    int year,n;
    cin>>year>>n;
    int t=year;
    while(true)
    {
        int cnt=1;
        int a=year/1000,b=year/100%10,c=year/10%10,d=year%10;
        if(a!=b&&a!=c&&a!=d) cnt++;
        if(b!=c&&b!=d) cnt++;
        if(c!=d) cnt++;
        if(cnt==n) break;
        year++;
    }
    printf("%d %04d",year-t,year);
}

L1-037 A除以B - 10

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

int main()
{
    double a,b;
    cin>>a>>b;
    if(b==0) printf("%.0f/%.0f=Error",a,b);
    else if(b<0) printf("%.0f/(%.0f)=%.2f",a,b,a/b);
    else printf("%.0f/%.0f=%.2f",a,b,a/b);
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值