竞赛评分

                               竞赛评分
时间限制:1000ms内存限制:65536kB
描述
现举行一次小竞赛,参赛的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.Scanner;  
  
public class Main {  
    public static void main(String[] args) {  
        Scanner sc = new Scanner(System.in);  
        int n = sc.nextInt();  
        String[][] an = new String[n][3];  
        for (int i = 0; i < n; i++)  
            for (int j = 0; j < 3; j++)  
                an[i][j] = sc.next();  
        int[] ch = new int[4];  
        for (int i = 0; i < 3; i++) {  
            int count = 0;  
            for (int j = 0; j < n; j++) {  
                if (an[j][i].equals("right"))  
                    count += 10;  
                if (an[j][i].equals("wrong"))  
                    count -= 10;  
            }  
            ch[i + 1] = count;  
        }  
        int max1 = 1;  
        for (int i = 1; i < 4; i++)  
            if (ch[i] > ch[max1])  
                max1 = i;  
        System.out.print("(" + max1 + "," + ch[max1] + ")");  
        int max2 = 0;  
        for (int i = 1; i < 4; i++)  
            if (i != max1) {  
                max2 = i;  
                break;  
            }  
        for (int i = 1; i < 4; i++)  
            if (i != max1 && i != max2 && ch[i] > ch[max2])  
                max2 = i;  
        if (ch[max2] < ch[max1])  
            System.out.println();  
        System.out.print("(" + max2 + "," + ch[max2] + ")");  
        int max3 = 0;  
        for (int i = 1; i < 4; i++)  
            if (i != max1 && i != max2) {  
                max3 = i;  
                break;  
            }  
        if (ch[max3]< ch[max2])  
            System.out.println();  
        System.out.print("(" + max3 + "," + ch[max3] + ")");  
  
    }  
  
}  


你可能感兴趣的:(JAVA基础题)