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

1069 微博转发抽奖 (20分)

从s-1开始计数,不要在一开始就count

代码

#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
//scanf printf防止超时
#include <algorithm>
//vector的sort
#include <sstream>
//转换
using namespace std;

#include<iomanip>
//精度

#include<cmath>
//round四舍五入取整

bool judge(string str,vector<string> strs)
{
    bool flag=true;
    for(int i=0;i<strs.size();i++)
    {
        if(strs[i]==str)
            flag=false;
    }
    return flag;
}
int main()
{
    int m,n,s;
    cin>>m>>n>>s;
    int count=0;
    vector<string> haveprice;
    for(int i=0;i<m;i++)
    {
        string str;
        cin>>str;
        if(i==s-1)
        {
            haveprice.push_back(str);
            count=0;
            //cout<<"count:"<<count<<endl;
        }
        if(i>=s)
        {
            if(count==n-1)
            {
                if(judge(str,haveprice))
                {
                    haveprice.push_back(str);
                    count=0;
                    //cout<<"count:"<<count<<endl;
                }
            }else
            {
                count++;
                //cout<<"count:"<<count<<endl;
            }

        }
    }
//cout<<"*****************"<<endl;
    if(haveprice.size()==0)
    {
        cout<<"Keep going..."<<endl;
    }else
    {
        for(int i=0;i<haveprice.size();i++)
        {
            cout<<haveprice[i]<<endl;
        }
    }
    return 0;
}
posted @ 2020-09-29 21:33  韩天尊  阅读(97)  评论(0)    收藏  举报