# 7-6 一帮一 (15分)

“一帮一学习小组”是中小学中常见的学习组织方式，老师把学习成绩靠前的学生跟学习成绩靠后的学生排在一组。本题就请你编写程序帮助老师自动完成这个分配工作，即在得到全班学生的排名后，在当前尚未分组的学生中，将名次最靠前的学生与名次最靠后的异性学生分为一组。

8
0 Amy
1 Tom
1 Bill
0 Cindy
0 Maya
1 John
1 Jack
0 Linda

Amy Jack
Tom Linda
Bill Maya
Cindy John

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.StringTokenizer;

//** Class for buffered reading int and double values *//*
static StringTokenizer tokenizer;

// ** call this method to initialize reader for InputStream *//*
static void init(InputStream input) {
tokenizer = new StringTokenizer("");
}

// ** get next word *//*
static String next() throws IOException {
while (!tokenizer.hasMoreTokens()) {
// TODO add check for eof if necessary
}
}
static boolean hasNext()throws IOException {
}
static String nextLine() throws IOException{
}
static char nextChar() throws IOException{
return next().charAt(0);
}
static int nextInt() throws IOException {
return Integer.parseInt(next());
}

static float nextFloat() throws IOException {
return Float.parseFloat(next());
}
}
public class Main {
public static void main(String[] args) throws IOException {

Person []persons = new Person[n];

for (int i = 0; i < persons.length; i++) {
persons[i] = new Person();
}
for (int i = 0; i < persons.length/2; i++) {

for (int j = persons.length-1; j >=0; j--) {
if (persons[i].sex+persons[j].sex==1&&persons[j].flag==0) {
System.out.println(persons[i].name+" "+persons[j].name);
persons[j].flag = 1;
break;
}
}

}
}
static class Person{
int sex;
String name;
int flag;
}
}



©️2019 CSDN 皮肤主题: 游动-白 设计师: 上身试试