微博转发抽奖

微博转发抽奖

1. 题目地址

    https://www.acwing.com/problem/content/1619/

2. 题目解析

    这道题整体来看,比较简单。仔细阅读题意即可。需要注意的是:当第一个中奖的人的序号大于总人数的时候,一定是没有中奖者的。此时需要输出Keep going....。
    判断某人是否中奖过,我们可以用一个unordered_map<string,bool>来存储。

3. 题解

    不再阐述。

4. 代码

#include <iostream>
#include <cstdio>
#include <vector>
#include <unordered_map>

using namespace std;


int m,n,s;

vector<string> persons;

unordered_map<string,bool> h;




int main(){
    scanf("%d%d%d",&m,&n,&s);
    for(int i = 0; i < m; i ++){
        string person;
        cin >> person;
        persons.push_back(person);
    }
    for(int i = s - 1; i < persons.size();){
        //如果该人中过奖
        while(i < persons.size() && h[persons[i]]){
            i++;
        }
        //如果越界
        if(i >= persons.size()){
            break;
        }
        //使得该人中奖,并输出
        h[persons[i]] = true;
        printf("%s\n",persons[i].c_str());
        //跳到下一个中奖者
        i+=n;
    }
    //如果第一位中奖者的序号大于总人数,那么一定没有中奖者。
    if(m < s){
        printf("Keep going...");
    }
    return 0;
}
posted @   夏目^_^  阅读(59)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示