PAT (Advanced Level) Practice A1124 Raffle for Weibo Followers (20 分) (map)

本文介绍了一个使用C++实现的抽奖程序,通过读取参与者名单并根据特定规则选择获奖者,确保了抽奖过程的公平性和效率。程序使用了标准模板库(STL)中的多种数据结构,如字符串、向量和映射,以及条件判断和循环控制结构。

原题链接

#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;

typedef long long int LL;
const int MAX = 1010, INF = 1<<30;

int M, N, S;
string name[MAX];
map<string, bool> flag;//注意不能用map<char*, bool> 

int main()
{
    scanf("%d %d %d", &M, &N, &S);
    for(int i=1; i<=M; i++)
    {
        cin>>name[i];
        flag[name[i]] = 0;
    }
    if(M < S) cout<<"Keep going..."<<endl;
    for(int j=S; j<=M; j+=N)
    {
        while(j<=M && flag[name[j]]) j++;//已经中过奖了,便考虑下一个
        if(j > M) break;
        cout<<name[j]<<endl;
        flag[name[j]] = 1;//置为已经中奖
    }
	return 0;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值