新生基础训练 第五题 汉字统计

Time Limit: 2000/1000 MS (Java/Others)
Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 62414
Accepted Submission(s): 33600

问题描述:
Problem Description
统计给定文本文件中汉字的个数。

Input
输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本。

Output
对于每一段文本,输出其中的汉字的个数,每个测试实例的输出占一行。

[Hint:]从汉字机内码的特点考虑~

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

Sample Output
14
9

Author
lcy

Source
C语言程序设计练习(五)

Recommend
lcy | We have carefully selected several similar problems for you: 2031 2032 2026 2027 2024

#include <iostream>
#include<string.h>
#include "stdio.h"
using namespace std;
int main()
{
	int n,i=0,j=0;
	char A[10000];
	cin>>n;
	while (n--)
	{
		int len;
		int m = 0;
		getchar();
		cin.getline(A,10000);
		len = strlen(A);
		for (i = 0; i < len; i++)
		{
			if (A[i] < 0) {
				m++; i++;
			}
		}
	   cout << m <<endl;
   }
   return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43981590/article/details/84979835
今日推荐