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. 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...
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <map>
 6 #include <stack>
 7 #include <vector>
 8 #include <queue>
 9 #include <set>
10 using namespace std;
11 const int MAX = 1e3 + 10;
12
13 int m, n, s, cnt = 0;
14 struct node
15 {
16     char s[30];
17 }P[MAX], S[MAX];
18 set <string> st;
19 pair <set <string> :: iterator, bool> pr;
20 set <string> :: iterator iter;
21
22 int main()
23 {
24 //    freopen("Date1.txt", "r", stdin);
25     scanf("%d%d%d", &m, &n, &s);
26     for (int i = 1; i <= m; ++ i)
27         scanf("%s", &P[i].s);
28
29     for (int i = s; i <= m; i += n)
30     {
31         pr = st.insert(P[i].s);
32         if (pr.second)
33         {
34             strcpy(S[cnt ++].s, P[i].s);
35             continue;
36         }
37         while (i <= m)
38         {
39             ++ i;
40             pr = st.insert(P[i].s);
41             if (pr.second)
42             {
43                 strcpy(S[cnt ++].s, P[i].s);
44                 break;
45             }
46         }
47     }
48
49     if (cnt == 0)
50     {
51         printf("Keep going...\n");
52         return 0;
53     }
54     for (int i = 0; i < cnt; ++ i)
55         printf("%s\n", S[i].s);
56     return 0;
57 }

原文地址:https://www.cnblogs.com/GetcharZp/p/9581881.html

时间: 2024-10-03 10:53:17

pat 1124 Raffle for Weibo Followers(20 分)的相关文章

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

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

PAT乙级:1057 数零壹 (20分)

PAT乙级:1057 数零壹 (20分) 题干 给定一串长度不超过 105 的字符串,本题要求你将其中所有英文字母的序号(字母 a-z 对应序号 1-26,不分大小写)相加,得到整数 N,然后再分析一下 N 的二进制表示中有多少 0.多少 1.例如给定字符串 PAT (Basic),其字母序号之和为:16+1+20+2+1+19+9+3=71,而 71 的二进制是 1000111,即有 3 个 0.4 个 1. 输入格式: 输入在一行中给出长度不超过 105.以回车结束的字符串. 输出格式: 在

pat 1136 A Delayed Palindrome(20 分)

1136 A Delayed Palindrome(20 分) Consider a positive integer N written in standard notation with k+1 digits a?i?? as a?k???a?1??a?0?? with 0≤a?i??<10 for all i and a?k??>0. Then N is palindromic if and only if a?i??=a?k?i?? for all i. Zero is written

pat 1054 The Dominant Color(20 分)

1054 The Dominant Color(20 分) Behind the scenes in the computer's memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A str

PAT 甲级 1027 Colors in Mars (20 分)(简单,进制转换)

1027 Colors in Mars (20 分) People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the

PAT A1076 Forwards on Weibo (30 分)——图的bfs

Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relations. When a user makes a post on Weibo, all his/her followers

PAT Basic 1069 微博转发抽奖 (20 分)

小明 PAT 考了满分,高兴之余决定发起微博转发抽奖活动,从转发的网友中按顺序每隔 N 个人就发出一个红包.请你编写程序帮助他确定中奖名单. 输入格式: 输入第一行给出三个正整数 M(≤ 1000).N 和 S,分别是转发的总量.小明决定的中奖间隔.以及第一位中奖者的序号(编号从 1 开始).随后 M 行,顺序给出转发微博的网友的昵称(不超过 20 个字符.不包含空格回车的非空字符串). 注意:可能有人转发多次,但不能中奖多次.所以如果处于当前中奖位置的网友已经中过奖,则跳过他顺次取下一位. 输