首页 > 其他 > 详细

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

时间:2020-09-29 23:16:36      阅读:45      评论:0      收藏:0      [点我收藏+]

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;
}

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

原文:https://www.cnblogs.com/zchq/p/13752050.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!