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

22真题

作者: 作者的头像   Ksiiiii ,  2024-11-28 21:28:47 ,  所有人可见 ,  阅读 1


0


无人机打靶

//很常规的结构体排序,直接三板斧就行,自定义swap,bubblesort,然后输出就好了
#include <iostream>
#include <string>

using namespace std;

const int N = 101;

struct airplane{
    string name;
    int score;
}P[N];

void swap(airplane &a,airplane &b){
    airplane t = a;
    a = b;
    b = t;
}

bool bubblesort(airplane P[],int n){
    for(int i = 0;i < n;i ++){
        bool flag = false;
        for(int j = 0;j < n - i -1;j ++){
            if(P[j].score < P[j+1].score){
                swap(P[j],P[j+1]);
                flag = true;
            }
        }
        if(!flag) break;
    }
}

int main(){
    int n ;
    cin >> n;
    int blue = 0;
    int red = 0;
    int green = 0;
    int purple = 0;
    for(int i = 0;i < n;i ++){
        cin >> P[i].name >> P[i].score;
        if(P[i].name == "b") blue ++;
        else if(P[i].name == "r") red ++;
        else if(P[i].name == "g") green ++;
        else if(P[i].name == "p") purple ++;
    }
    cout << blue <<endl << red <<endl<< green <<endl<< purple << endl;
    bubblesort(P,n);
    for(int j = 0;j < n;j ++){
        cout << P[j].score << " "<< P[j].name <<endl;
    }
    return 0;
}

扑克牌中的顺子

#include <iostream>
#include <algorithm>

using namespace std;

// 判断五张牌是否构成顺子的函数
bool isStraight(int nums[5]) {
    int appeared[14] = {0};  // 用于模拟记录牌面数值是否出现过,索引对应牌面数值(0 - 13),初始化为0表示都未出现
    int maxVal = 0;
    int minVal = 14;
    for (int i = 0; i < 5; i++) {
        int num = nums[i];
        if (num == 0) {
            continue;
        }
        // 如果对应牌面数值已经标记为出现过(即appeared[num]为1),说明有重复牌,返回false
        if (appeared[num]) {
            return false;
        }
        appeared[num] = 1;  // 将对应牌面数值标记为已出现
        maxVal = max(maxVal, num);
        minVal = min(minVal, num);
    }
    return maxVal - minVal < 5;
}

int main() {
    int inputCards[5];
    for (int i = 0; i < 5; i++) {
        cin >> inputCards[i];
    }

    if (isStraight(inputCards)) {
        cout << "这五张牌是顺子" << endl;
    } else {
        cout << "这五张牌不是顺子" << endl;
    }

    return 0;
}

计算机视觉(递归实现指数型枚举)

0 评论

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

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