1124. Raffle for Weibo Followers (20)

13 篇文章 7 订阅
  1. 题目见这里

  2. 用链表保存Followers,每个插入链表的对象对应一个flag(初值为false),必须输出对象后才能置flag为true,注意每次输出必须保证tmp<s(tmp为有效对象个数)

  3. 代码如下:

#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;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值