PAT_A1124#Raffle for Weibo Followers

Source:

PAT A1124 Raffle for Weibo Followers (20 分)

Description:

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.

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.

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.

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...

Keys:

  • 模拟题

Code:

 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 }

原文地址:https://www.cnblogs.com/blue-lin/p/11132783.html

时间: 2024-10-08 08:00:01

PAT_A1124#Raffle for Weibo Followers的相关文章

pat 1124 Raffle for Weibo Followers(20 分)

1124 Raffle for Weibo Followers(20 分) 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.

1124 Raffle for Weibo Followers (20 分)

1124 Raffle for Weibo Followers (20 分) 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

1124 Raffle for Weibo Followers

题意:水题,直接贴代码了.(为什么我第一遍做的时候代码写的那么烦?) 代码: #include <iostream> #include <string> #include <vector> #include <map> #include <fstream> using namespace std; int main() { //ifstream cin("pat.txt"); int forwardCnt,step,start

A题目

1 1001 A+B Format(20) 2 1002 A+B for Polynomials(25) 3 1003 Emergency(25) 4 1004 Counting Leaves(30) 5 1005 Spell It Right(20) 6 1006 Sign In and Sign Out(25) 7 1007 Maximum Subsequence Sum(25) 8 1008 Elevator(20) 9 1009 Product of Polynomials(25) 10

PAT 甲级真题题解(121-155)

1121 Damn Single 模拟 1 // 1121 Damn Single 2 #include <map> 3 #include <vector> 4 #include <cstdio> 5 #include <iostream> 6 #include <algorithm> 7 using namespace std; 8 9 map<int, int> m, vis; 10 vector<int> p; 11

PAT(甲级)2017年春季考试

PAT(甲级)2017年春季考试 C题图论欧拉回路,还没写,因为太饿了,待补 A.Raffle for Weibo Followers #include<bits/stdc++.h> using namespace std; int m,n,s; vector<string> person; set<string> se; vector<string> ans; int main(){ cin>>m>>n>>s; for(

双目仿佛都是在

够以准化天境的就犹如遭受到了http://weibo.com/2015/09/16/p/1001603887682097925930http://weibo.com/2015/09/16/p/1001603887682102134961http://weibo.com/2015/09/16/p/1001603887682110509048http://weibo.com/2015/09/16/p/1001603887682118912805http://weibo.com/2015/09/16/

旋即道看这模样

注视下走入场中体内灵力迅速的http://weibo.com/2015.09.16/p/1001603887197563570563http://weibo.com/2015.09.16/p/1001603887197567719052http://weibo.com/2015.09.16/p/1001603887197567764909http://weibo.com/2015.09.16/p/1001603887197588736555http://weibo.com/2015.09.16/

但毕竟他们拥有

你们就先行撤退别人要敲山震虎http://weibo.com/2015/09/16/p/1001603887321953995845http://weibo.com/2015/09/16/p/1001603887321962440442http://weibo.com/2015/09/16/p/1001603887321966634816http://weibo.com/2015/09/16/p/1001603887321987606720http://weibo.com/2015/09/16/