[Explanations] - hdu Character Statistics

## characters statistics

Statistics for the number of characters in a given text file.

####Input

A first input file contains the integer n, the number of test examples, then the n pieces of text.

####Output

For each piece of text, wherein the number of output characters, the output of each test case in one row.
[Hint:] Features Chinese machine code from consideration ~

####Sample Input

2
WaHaHa! WaHaHa! 今年过节不说话要说只说普通话WaHaHa! WaHaHa!
马上就要期末考试了Are you ready?

####Sample Output

14
9

Code

#include <stdio.h>
#include <string.h>
int main(void)
{
    int n, i, sum;
    char arr[1005];
    scanf("%d",&n);
    getchar();
    while(n --){
        gets(arr);
        for(i = 0, sum = 0; i < strlen(arr); i ++){
            if(arr[i] == '\n') break;
            if(arr[i] < 0){
                sum ++;
            }
        }
        printf("%d\n",sum / 2);
    }
    return 0;
}

annotation

Case of a general topic description would not char arr [1005]

Note that this judgment is not that characters arr [i] <0 || arr [i]> 127

Published 34 original articles · won praise 2 · Views 933

Guess you like

Origin blog.csdn.net/Kapo1/article/details/103481873
Recommended