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

pat 1124 Raffle for Weibo Followers(20 分)相关推荐

  1. 【PAT (Advanced Level) Practice】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 ...

  2. PAT_A 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 t ...

  3. PAT 1124 Raffle for Weibo Followers

    PAT 1124 Raffle for Weibo Followers Java 1.题意 输入:数字m,n,s,一串人名. 第s个为获奖的人,则s+n 为下一个获奖的人,如果此人已经获奖,那么则往后 ...

  4. PAT 1124 Raffle for Weibo Followers python解法

    1124 Raffle for Weibo Followers (20 分) John got a full mark on PAT. He was so happy that he decided ...

  5. PTA甲1124 Raffle for Weibo Followers (20 point(s))

    强烈推荐,刷PTA的朋友都认识一下柳神–PTA解法大佬 本文由参考于柳神博客写成 柳神的CSDN博客,这个可以搜索文章 柳神的个人博客,这个没有广告,但是不能搜索 还有就是非常非常有用的 算法笔记 全 ...

  6. PAT-1124. Raffle for Weibo Followers (20)

    1124. Raffle for Weibo Followers (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN ...

  7. PAT甲级1124 Raffle for Weibo Followers :[C++题解]哈希表、微博转发抽奖

    文章目录 题目分析 题目来源 题目分析 来源:acwing 分析:开一个哈希表存已经中将的用户,避免重复发奖. 遍历所有m条姓名,从第一个中奖的开始,依次模拟即可. ac代码 #include< ...

  8. PAT(甲)1124 Raffle for Weibo Followers——未完成

    题目链接 按Ctrl单机链接,打开题目页面. 做题过程 题目分值 20 分 提交次数 分值 原因 解决方案 1 12 答案错误 重复n次 2 12 答案错误 未解决 收获:基本错题是通过样例猜题意,然 ...

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

最新文章

  1. 解题报告 - 牛客练习赛63 C - 牛牛的揠苗助长(货仓选址+二分)
  2. 百度编辑器(ueditor)上传图片
  3. [书目20130216]深入浅出WPF
  4. Power Designer使用技巧
  5. 细说SSO单点登录(转)
  6. 自主学习之RxSwift(二) -----flatMap
  7. 数据流程图顶层一层二层_只需三个公式,三阶魔方超简单入门图文教程5:完全复原第二层...
  8. 快速对比UART、SPI、I2C通信的区别与应用
  9. java quartz tomcat_Quartz Scheduler - 在Tomcat或应用程序jar中运行?
  10. list、tuple、dict、set、map
  11. Android环境配置(Eclipse全开发环境下载)
  12. 研磨设计模式--简单工厂
  13. CMS-订单系统的分布式事务如何处理
  14. vs13配置matlab,VS配置电脑系统变量(VS2013+matlab2018a)
  15. Macbook变速播放视频
  16. 4G模块的GPS定位差距过大
  17. 亿级视频内容如何实时更新?
  18. win10 cortana搜索没有任何结果,只是一片空白的解决方案
  19. 用断点续存实现视频快速上传
  20. c语言 爱心 (koi奋斗中~~)

热门文章

  1. java调用bat脚本实现pppoe拨号_pppoe客户端自动拨号原理及实现
  2. discuz 模板代码解释
  3. c语言cfree编程步骤,C语言初探之利用C-Free编写C语言
  4. es6,es7,webpack 和 babel(爱前端)
  5. linux指令(一、目录与档案)
  6. console.log(console.log) = ?
  7. 《电子病历系统》管理员手册
  8. typeof与keyof
  9. Shoprxr 开源电商系统
  10. 大数据学习之小白快速了解flume