7-2 Floor grab

Blizzard’s anniversary, launched a building and floor grab activity in the forum. The lucky ones got a sigh of Frost, so everyone flocked to them and started grabbing floors. Your task is to find the lucky ones.

Input format:

In the first line, enter three integers N, K, S, N is the total number of floors, no more than 1000, K is the number of floors separated by the lucky person, S is the number of the first lucky person, and the floors start from 1. The next N lines are the nicknames of the followers on each floor. The nickname is a string of no more than 20 characters without spaces. The matter was originally simple, but Frost Sigh was too tempting, so many people repeated postings, hoping to grab the floor, but Blizzard stipulates that each person can only get 1 Frost Sigh. If you have already passed it, then It's about to skip

Output format:

For each set of input, output the nickname of the lucky person, one per line, if no one is selected, output No one was chosen.

Input example 1:

10 3 1
Underneath
Weddinginthedream
Queen
WaitingforLove
Drinktowind
Bodyontheocean
Dark
Lolita
Thedreamofyou
Smilelikeflower

Output sample 1:

Underneath
WaitingforLove
Dark
Smilelikeflower

Input example 2:

2 3 3
Underneath
Weddinginthedream

Output sample 2:

No one was chosen

Analysis: There is nothing to analyze, apply for a clear question, and it will be finished. Ori gave the
AC code:

#include<bits/stdc++.h>
using namespace std;
int t=0;
string a;
string s[200];        //获奖人名数组
bool judge(string a)         
{
    
    
 	for(int i=0;i<t;i++)
  		if(a==s[i])
   			return false;
 	return true;
}
int main()
{
    
    
	int N,K,S;
	cin>>N>>K>>S;
	if(S>N)
	{
    
    
		cout<<"No one was chosen\n";
		return 0; 
 	}
 	for(int i=1;;i++)
 	{
    
    
 		cin>>a;
  		if(i==S)
  		{
    
    
   			cout<<a<<endl;
   			s[t++]=a;//控制查重判定范围
   			break;
  		}
 	}
 	int count=1;
 	for(int i=S+1;i<=N;i++)   
 	{
    
    
  		cin>>a;
  		if(count%K==0)
  		{
    
    
   			if(judge(a)) 
   			{
    
    
    				cout<<a<<endl;
    				s[t++] = a;
   			}
   			else 
    				continue;
  		}
  		count++;
 	} 
 	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_45989486/article/details/108537630