【PAT】1124. Raffle for Weibo Followers (20)【Map使用】

题目描述

John got a full mark on PAT. He was so happy that he decided to hold a raffle(抽奖) for his followers on Weibo – that is, he would select winners from every N followers who forwarded his post, and give away gifts. Now you are supposed to help him generate the list of winners.

翻译:约翰在PAT考试中得了满分。他非常高兴,所以决定为他在微博上的粉丝举行一次抽奖活动——也就是说,他会从每N个转发他的微博的粉丝选择中奖者然后赠送礼物。现在你需要帮助他生成获奖名单。

Input Specification:

Each input file contains one test case. For each case, the first line gives three positive integers M (≤ 1000), N and S, being the total number of forwards, the skip number of winners, and the index of the first winner (the indices start from 1). Then M lines follow, each gives the nickname (a nonempty string of no more than 20 characters, with no white space or return) of a follower who has forwarded John’s post.

Note: it is possible that someone would forward more than once, but no one can win more than once. Hence if the current candidate of a winner has won before, we must skip him/her and consider the next one.

翻译:每个输入文件包含一组测试数据。对于每组测试数据,第一行给出3个正整数M (≤ 1000),N和S,分别表示粉丝个数,中奖者之间间隔的个数和第一个中奖者的编号(编号从1开始)。接着M行,每行给出一位转发了John的微博的粉丝的昵称(一个不超过20个字符的没有空格和回车的字符串)。

Output Specification:

For each case, print the list of winners in the same order as in the input, each nickname occupies a line. If there is no winner yet, print Keep going… instead.

翻译:对于每组测试数据,按照输入的相同顺序输出中奖者的编号,每个昵称占一行。如果没有中奖者,则输出Keep going… 。


Sample Input 1:

9 3 2
Imgonnawin!
PickMe
PickMeMeMeee
LookHere
Imgonnawin!
TryAgainAgain
TryAgainAgain
Imgonnawin!
TryAgainAgain


Sample Output 1:

PickMe
Imgonnawin!
TryAgainAgain


Sample Input 2:

2 3 5
Imgonnawin!
PickMe


Sample Output 2:

Keep going…


解题思路

STLmap模板题,使用map集合保存每个人的编号,然后按照题目模拟。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<map> 
#include<algorithm>
#define INF 99999999
using namespace std;
map<string,int> mp;
string peo[1010];
int ccount=1,M,N,S;
int f[1010],F[1010];
int main(){
	scanf("%d%d%d",&M,&N,&S);
	string str;
	for(int i=1;i<=M;i++){
		cin>>str;
		if(!mp[str]){
			mp[str]=ccount;
			peo[ccount]=str;
			f[i]=ccount;
			ccount++;
		}else{
			f[i]=mp[str];
		}
	}
	ccount=0;
	for(int i=S;i<=M;i++){
		if(ccount%N==0&&!F[f[i]]){
			F[f[i]]=1;
			cout<<peo[f[i]]<<endl;
			ccount++;
		}
		else if(!F[f[i]]){
			ccount++;
		}
	}
	if(S>M)cout<<"Keep going..."<<endl;
	return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值