Chinese character statisticsTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 30230 Accepted Submission (s): 16588
problem Descriptioncounts the number of Chinese characters in a given text file.
InputThe input file first contains an integer n, which indicates the number of test instances, followed by the N-segment text.
Outputfor each piece of text, output the number of Chinese characters, and one row for each test instance.
[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
AuthorLCY
SourceC language Programming exercises (v)Ideas:
because the ASCII code of the Chinese characters are negative, and each Chinese character accounted for two bytes, it will be counted less than 0 of the number divided by 2 to get the desired result!
Code:
/* *************************************************************************** * * * * file name: HDU2027201507231707 * * Created by: New * * Date : July 23, 2015 17:07:25 * * Function Description: Statistics of the number of characters in a given text * * Version : Dev C + + * Modified by: NEW * * * * * * * * * * * * * * * * * * */ #include <stdio.h># Include <string.h>int main () {char a[1000];int n,i,j,k,t;scanf ("%d", &n), GetChar (); while (n--) {gets (a); t= Strlen (a); for (i=0,j=0;i<t;i++) {if (a[i]<0)
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 2027 Kanji Statistics