标签:sample 打印 desc target == inf nta ios using
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.
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.
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.
9 3 2 Imgonnawin! PickMe PickMeMeMeee LookHere Imgonnawin! TryAgainAgain TryAgainAgain Imgonnawin! TryAgainAgain
PickMe Imgonnawin! TryAgainAgain
2 3 5 Imgonnawin! PickMe
Keep going...
1 /* 2 Data: 2019-07-04 15:00:05 3 Problem: PAT_A1124#Raffle for Weibo Followers 4 AC: 25:52 5 6 题目大意: 7 从转发微博的名单中抽奖,每隔N人送一份奖品 8 输入: 9 第一行给出,转发数M<=1000,获奖者间隔的人数N,第一个获奖者序号S>=1 10 接下来M行,转发人的昵称 11 注:若选定的获奖者如果已经获奖,则考虑下一个人 12 输出: 13 打印获奖者名单 14 15 基本思路: 16 从S开始遍历名单,计数器统计跳过人数,跳过n人时进行查询 17 若未获奖,计数器清零,打印姓名 18 若已获奖,计数器不变,查询下一位 19 */ 20 #include<cstdio> 21 #include<string> 22 #include<map> 23 #include<iostream> 24 using namespace std; 25 const int M=1e3+10; 26 string info[M]; 27 map<string,int> mp; 28 29 int main() 30 { 31 #ifdef ONLINE_JUDGE 32 #else 33 freopen("Test.txt", "r", stdin); 34 #endif 35 36 int m,n,s,skip=0; 37 scanf("%d%d%d", &m,&n,&s); 38 for(int i=1; i<=m; i++) 39 cin >> info[i]; 40 for(int i=s; i<=m; i++) 41 { 42 if(i==s || skip==n) 43 { 44 if(mp[info[i]]==0){ 45 cout << info[i] << endl; 46 mp[info[i]]=1; 47 skip=0; 48 } 49 else 50 continue; 51 } 52 skip++; 53 } 54 if(s > m) 55 printf("Keep going..."); 56 57 return 0; 58 }
PAT_A1124#Raffle for Weibo Followers
标签:sample 打印 desc target == inf nta ios using
原文地址:https://www.cnblogs.com/blue-lin/p/11132783.html