How to view the number of Chinese characters calculation method Hangzhou Electric 2030

Source: Internet
Author: User
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 input2wahaha! wahaha! This year the festival does not speak to speak only Putonghua wahaha! Wahaha! 's going to take the final exams right now.

#include <stdio.h>
#include <string.h>
int main ()
{
Char a[1000];
int n,i,s;
scanf ("%d", &n);
while (n--)
{
Gets (a);
s=0;
For (I=0;i<strlen (a); i++)
{
if (a[i]<0)//The ASCII of Chinese characters is less than 0!!!
s++;
}
printf ("%d\n", S/2);/Kanji takes two bytes, so divide by 2!!!
}
return 0;
}

How to view the number of Chinese characters calculation method Hangzhou Electric 2030

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.