import java.io.*;
public class pat1069 {
static String[] winners = new String[1001]; //记录中奖者名单
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] arr = br.readLine().trim().split(" ");
int M = Integer.parseInt(arr[0]);
int N = Integer.parseInt(arr[1]);
int S = Integer.parseInt(arr[2]);
int winnerNum = 0;
for(int i=1;i<=M;i++) { //循环9次
String name = br.readLine();
if(i<S) continue; //如果还没到第一个中奖人员,continue
int loc = find(name);
if(loc==-1) continue; //如果已经存在,contune
winners[loc] = name; //把名字插入
winnerNum++;
System.out.println(name);
for(int j=1;j<N;j++) {
i++;
String nextName = br.readLine();
}
}
if(winnerNum==0) System.out.println("Keep going...");
}
private static int find(String name) {
for(int i=0;i<1001;i++) {
if(winners[i]==null) return i;
if(winners[i].equals(name)) return -1;
}
return -1;
}
}
PAT乙级 1069 微博转发抽奖 (20 分) Java 实现
最新推荐文章于 2024-09-13 17:30:19 发布
该Java程序设计了一个彩票抽奖系统,每次循环读取输入的姓名,并根据设定的中奖规则决定是否为中奖者。程序跳过前S个名额,然后在剩余的M-S个人中,每N个人产生一个中奖者。如果在整个过程中没有中奖者,则输出'Keep going...'。程序使用了字符串数组来存储中奖者名单,并通过查找函数避免重复中奖。
摘要由CSDN通过智能技术生成