1124. Raffle for Weibo Followers (20)
2017-08-09 13:40
393 查看
题目见这里
用链表保存Followers,每个插入链表的对象对应一个flag(初值为false),必须输出对象后才能置flag为true,注意每次输出必须保证tmp
代码如下:
用链表保存Followers,每个插入链表的对象对应一个flag(初值为false),必须输出对象后才能置flag为true,注意每次输出必须保证tmp
<s(tmp为有效对象个数)
代码如下:
#include <iostream> #include <string> #include <list> using namespace std; const int M = 1005; int main(){ // freopen("Data.txt","r",stdin); list<string> forwards; bool flag[M]={false}; //某字符串是否输出 string forward; int m,n,s,tmp,index,i; cin >> m >> n >> s; tmp = 0; for(i=1;i<=m;i++){ cin >> forward; if(m<s) continue; //no winners index = 0; list<string>::iterator iter; for(iter=forwards.begin();iter!=forwards.end();iter++){ index ++; if(*iter==forward) break; } if(!hash[index] || iter==forwards.end()){ if(iter==forwards.end()){ forwards.push_back(forward); //尾部插入 index ++; } tmp ++; if(tmp<s) continue; //反例:11 2 4(输出第二个,不加判断的话) if(!((tmp-s)%n)){ cout << forward << '\n'; flag[index] = true; } } } if(m<s) cout << "Keep going..." << '\n'; return 0; }
相关文章推荐
- PAT甲级 1124. Raffle for Weibo Followers (20)
- PAT (Advanced Level) 1124. Raffle for Weibo Followers (20) 解题报告
- 1124. Raffle for Weibo Followers (20) PAT 甲级&&1069. 微博转发抽奖(20) PAT乙级
- 1124. Raffle for Weibo Followers (20)
- 1124. Raffle for Weibo Followers (20)
- PAT (Advanced Level) Practise 1124 Raffle for Weibo Followers (20)
- PAT 1124. Raffle for Weibo Followers (20)
- 1124. Raffle for Weibo Followers (20) 模拟
- PAT 1124. Raffle for Weibo Followers (20) 模拟微博抽奖,Set应用
- 1124. Raffle for Weibo Followers (20)
- 1124. Raffle for Weibo Followers (20)[数学逻辑题]
- 【PAT】【Advanced Level】1124. Raffle for Weibo Followers (20)
- 1124. Raffle for Weibo Followers (20)
- 1124. Raffle for Weibo Followers (20)
- PAT:1124. Raffle for Weibo Followers (20)
- PAT 甲级 1124. Raffle for Weibo Followers (20)
- 1124. Raffle for Weibo Followers (20)
- 1124. Raffle for Weibo Followers (20)
- 1124. Raffle for Weibo Followers (20)
- PAT_A 1124. Raffle for Weibo Followers (20)