1. 程式人生 > >2018/12/06 L1-030 一幫一 Java

2018/12/06 L1-030 一幫一 Java

考察理解題目的能力, 上程式碼:

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; } } }