AcWing
  • 首页
  • 课程
  • 题库
  • 更多
    • 竞赛
    • 题解
    • 分享
    • 问答
    • 应用
    • 校园
  • 关闭
    历史记录
    清除记录
    猜你想搜
    AcWing热点
  • App
  • 登录/注册

22-真题

作者: 作者的头像   把头发掀起来看世界 ,  2024-11-22 20:39:58 ,  所有人可见 ,  阅读 1


0


1.无人机打耙

#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N=40;

int b,r,g,p;
struct robot
{
    string color;
    int score;
    bool operator< (const robot &t)const {
        return score>t.score;
    }
}ro[N];

int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        char c;
        cin>>c>>ro[i].score;
        if(c=='b') {b++;ro[i].color="blue";}
        else if(c=='r') {r++;ro[i].color="red";}
        else if(c=='g') {g++;ro[i].color="green";}
        else {p++;ro[i].color="purple";}
    }

    cout<<"blue"<<" "<<b<<endl;
    cout<<"green"<<" "<<g<<endl;
    cout<<"purple"<<" "<<p<<endl;
    cout<<"red"<<" "<<r<<endl;

    sort(ro,ro+n);
    for(int i=0;i<n;i++)
        cout<<ro[i].score<<" "<<ro[i].color<<endl;

    return 0;
}

2.顺子

#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <vector>
using namespace std;

bool isStraight2(vector<int>& num)
{
    int ma=-1,mi=15,w=0,n=0;
    unordered_set<int> s;
    for(int x:num)
    {
        if(x==0) {w++;continue;}
        ma=max(ma,x);
        mi=min(mi,x);
        if(s.count(x)) return false;
        else 
        {
            s.insert(x);
            n++;
        }
    }

    int d=ma-mi+1;
    if(n==5 && d==5)return true;
    else if(n==4 && (d==5 ||d==4))return true;
    else if(n==3 && (d>=3||d<=5))return true;
    else return false;

}
int main()
{
    vector<int> num(5);

    for(int i=0;i<5;i++)
    {
        char x;
        cin>>x;
        if(x=='A')num[i]=1;
        else if(x=='J')num[i]=11;
        else if(x=='Q')num[i]=12;
        else if(x=='K')num[i]=13;
        else if(x=='W'||x=='w')num[i]=0;
        else num[i]=x-'0';
    }

    if(isStraight2(num))cout<<"顺子"<<endl;
    else cout<<"不是顺子"<<endl;
    return 0;
}

0 评论

App 内打开
你确定删除吗?
1024
x

© 2018-2025 AcWing 版权所有  |  京ICP备2021015969号-2
用户协议  |  隐私政策  |  常见问题  |  联系我们
AcWing
请输入登录信息
更多登录方式: 微信图标 qq图标 qq图标
请输入绑定的邮箱地址
请输入注册信息