从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