【ACM】HDU 1004 Let the Balloon Rise (for java)

版权声明:MZ21G https://blog.csdn.net/qq_35793285/article/details/84678306

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner scanner = new Scanner(System.in);
				
		while (scanner.hasNext()) {
			
			String[] str = new String[1001];	
			int[] count = new int[1001];    // 计数声明初始化为1
			for (int i = 0; i <= 1000; i++) {
				count[i] = 1;
			}
			
			int N = scanner.nextInt();
			if (N == 0) {
				break;
			}
			for (int i = 0; i < N; i++) {
				String per_str = scanner.next();
				str[i] = per_str;
				
				if (i >= 1) {
					for (int j = 0; j <= i; j++) {				
						if (str[i].equals(str[j])) {
							count[j]++;
						}					
					}			
				}	
				
			}
			int max = count[0], index = 0;
			for (int i = 0; i < count.length; i++) {
				if (count[i] > max) {
					max = count[i];
					index = i;
				}			
			}
			
			System.out.println(str[index]);

	
		}	
	}
}

猜你喜欢

转载自blog.csdn.net/qq_35793285/article/details/84678306
今日推荐