1124 Raffle for Weibo Followers

博客分享了一道C/C++水题的代码,作者感慨第一遍做时代码写得繁琐,代码转载自https://www.cnblogs.com/kkmjy/p/9538875.html 。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:水题,直接贴代码了。(为什么我第一遍做的时候代码写的那么烦?)

代码:

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <fstream>
using namespace std;

int main()
{
    //ifstream cin("pat.txt");
    int forwardCnt,step,start;
    cin>>forwardCnt>>step>>start;
    string name;
    vector<string> vec(forwardCnt),win;
    map<string,int> mp;//标记已获奖的人
    int skip=step;
    for(int i=0;i<forwardCnt;i++)
        cin>>vec[i];
    if(start>vec.size()) cout<<"Keep going...";
    else{
        int i=start-1;//从第一个中奖者开始
        while(i<vec.size()){
            string query=vec[i];
            if(mp[query]==0){//该用户在此前还没有获过奖
                win.push_back(query);
                mp[query]=1;
                i+=step;
            }else{
                i++;
            }
        }
        for(auto it:win)//可以用C++11,方便
            cout<<it<<'\n';
    }
    return 0;
}

 

转载于:https://www.cnblogs.com/kkmjy/p/9538875.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值