PAT甲题题解-1124. Raffle for Weibo Followers-模拟,水题

水题一个,贴个代码吧。

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>

using namespace std;
const int maxn=1005;
map<string,int> maps;
int main()
{
    int n,m,s;
    string str;
    scanf("%d %d %d",&m,&n,&s);
    int cnt=0;
    if(m<s){
        printf("Keep going...\n");
    }
    else{
        for(int i=0;i<s;i++)
            cin>>str;
        maps[str]=1;
        cout<<str<<endl;
        for(int i=s;i<m;i++){
            cin>>str;
            cnt++;
            if(cnt==n){
                if(!maps[str]){
                    maps[str]=1;
                    cnt=0;
                    cout<<str<<endl;
                }
                else
                    cnt--;
            }
        }

    }

    return 0;
}
View Code

 

posted @ 2017-03-05 19:40  辰曦~文若  阅读(256)  评论(0编辑  收藏  举报