Problem:
Java is more complex in judging Chinese.
Chinese character statisticsTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 29746 Accepted Submission (s): 16314
Problem description counts the number of Chinese characters in a given text file.
The input file first contains an integer n, which indicates the number of test instances, followed by the N-segment text.
Output for each piece of text, outputs the number of characters in it, and the output of each test instance takes one row.
[Hint:] From the characteristics of the Chinese character machine internal code to consider ~
Sample Input
2wahaha! wahaha! This year the festival does not speak to speak only Putonghua wahaha! Wahaha! 's going to take the final exams right now.
Sample Output
149
Code:
Import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in); int n=cin . Nextint (); String S;cin.nextline (); for (int i=0;i<n;i++) {s=cin.nextline (); char[] A=s.tochararray (); int count=0;for (int j=0;j <s.length (); j + +) {Character.unicodeblock UB = Character.UnicodeBlock.of (A[j]); if (UB = = Character.UnicodeBlock.CJK _unified_ideographs| | UB = = character.unicodeblock.cjk_compatibility_ideographs| | UB = = character.unicodeblock.cjk_unified_ideographs_extension_a| | UB = = character.unicodeblock.general_punctuation| | UB = = character.unicodeblock.cjk_symbols_and_punctuation| | UB = = Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) count++;} System.out.println (count);}}}
HDU 2030 Kanji Statistics (Java)