51:竞赛评分
描述
现举行一次小竞赛,参赛的3支队伍,编号为1,2,3.每支队列轮流回答问题,如果回答正确,加10分;回答错误,扣10分;放弃回答不得分.经过多轮答题后,我们要统计各队的名次和得分.
输入
第一行为回答问题的轮次数n.其余各行分别为1,2,3号队伍答题的结果,回答正确为right,错误为wrong,放弃为give-up.
输出
按名次输出各队的编号和得分.名次相同的在同一行输出,且编号小者靠前.
样例输入
4
right wrong give-up
right right right
wrong right right
right right right
样例输出
(3,30)
(1,20)(2,20)
代码
import java.util.*;
import java.math.*;
class student
{
public int id;
public int zf;
student(int id)
{
this.id = id;
zf = 0;
}
}
class zfsort implements Comparator<student>
{
public int compare(student o1, student o2)
{
if(o1.zf == o2.zf)
return o1.id - o2.id;
return o2.zf - o1.zf;
}
}
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
student[] people = new student[3];
for(int i = 0; i < 3; i++)
people[i] = new student(i+1);
for(int i = 1; i <= n; i++)
{
String s1 = cin.next();
String s2 = cin.next();
String s3 = cin.next();
if(s1.equals("right"))
people[0].zf += 10;
else if(s1.equals("wrong"))
people[0].zf -= 10;
if(s2.equals("right"))
people[1].zf += 10;
else if(s2.equals("wrong"))
people[1].zf -= 10;
if(s3.equals("right"))
people[2].zf += 10;
else if(s3.equals("wrong"))
people[2].zf -= 10;
}
Arrays.sort(people,new zfsort());
if(people[0].zf == people[1].zf)
{
System.out.print("("+people[0].id+","+people[0].zf+")");
System.out.print("("+people[1].id+","+people[1].zf+")");
}
else
{
System.out.println("("+people[0].id+","+people[0].zf+")");
System.out.print("("+people[1].id+","+people[1].zf+")");
}
if(people[1].zf == people[2].zf)
System.out.print("("+people[2].id+","+people[2].zf+")");
else
{
System.out.println();
System.out.print("("+people[2].id+","+people[2].zf+")");
}
}
}