一开始并没有做出来,关键是没有认真理解题,每次做题之前都应该认真读题,自己把样例模拟一下,防止漏掉信息,减慢自己写代码的速度
此题的重点在于规划逻辑,以及如何储存中奖者,用map最好,否则查找并不方便,

#include<cstdio>
#include<string.h>
#include<iostream>
#include<map>
using namespace std;
int main(){
    int M,N,S,flag=0,flag1=0;
    scanf("%d %d %d",&M,&N,&S);
    map<string,int> mp;//存储中奖者
    for(int i=1;i<=M;i++){
		string temp;cin>>temp;
		if(i==S){//第一个中奖者
			cout<<temp<<endl;
            mp[temp]=1;
		}
		if(i>S){//第一个中奖者之后的人
			flag1++;
			if(flag1==N){
				if(mp.count(temp)==0){//当前没领过
					mp[temp]=1;
					cout<<temp<<endl;
					flag1=0;
				}else
					flag1--;
			}
		}
    }
    if(mp.size()==0) printf("Keep going...\n");
    return 0;
}

相关文章:

  • 2022-12-23
  • 2022-01-02
  • 2021-05-27
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-12-20
  • 2021-10-22
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2021-06-20
相关资源
相似解决方案