考察理解题目的能力, 上代码:
import java.io.BufferedReader; import java.io.InputStreamReader; public class Main { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int num = Integer.parseInt(br.readLine()); int oneNum = 0; int zeroNum = 0; String[][] str = new String[num][2]; if (num >= 2 && num <= 50) { for(int i=0; i<num; i++) { str[i] = br.readLine().split(" "); if( Integer.parseInt(str[i][0]) == 1) { oneNum++; } else if(Integer.parseInt(str[i][0]) == 0) { zeroNum++; } else { return; } } if (oneNum == zeroNum) { for(int i=0; i<num; i++) { for(int j=num-1; j>0; j--) { if(!str[i][0].equals(str[j][0]) && !str[i][0].equals("-1") && !str[j][0].equals("-1")) { System.out.println(str[i][1] + " " + str[j][1]); str[i][0] = "-1"; str[j][0] = "-1"; break; } } } } else { return; } } else { return; } } }
原文地址:https://www.cnblogs.com/huangZ-H/p/10079498.html
时间: 2024-11-11 12:38:08