杭电ACM----统计汉字的个数

题目:统计汉字的个数

package edu.hangdian.se.num2030;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main2030 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNextInt()) {
			int count = sc.nextInt();
			sc.nextLine();
			String line = null;
			List list = new ArrayList();
			for (int i = 0; i < count; i++) {
				if (sc.hasNextLine()) {
					line = sc.nextLine();
					list.add(statistics(line));
				}
			}
			for (Integer integer : list) {
				System.out.println(integer);
			}
		}
	}

	private static Integer statistics(String line) {
		int sum = 0;
		// String reg = "^[\u4e00-\u9fa5]{1}$";
		for (int i = 0; i < line.length(); i++) {
			// if (line.charAt(i) >= 19968 && line.charAt(i) <= 64041) {
			// sum++;171941
			// }
			if (line.charAt(i) >= 19968 && line.charAt(i) <= 171941) {
				sum++;
			}
			// String temp = Character.toString(line.charAt(i));
			// if (temp.matches(reg)) {
			// sum++;
			// }

			// Pattern pattern = Pattern.compile("[\u4E00-\u9FA5]");
			// Matcher matc = pattern.matcher(str);
			// StringBuffer stb = new StringBuffer();
			// while (matc.find()) {
		}
		return sum;
	}
}


你可能感兴趣的:(编程记录)