首页 > 其他 > 详细

汉字统计

时间:2019-05-01 21:34:35      阅读:144      评论:0      收藏:0      [点我收藏+]



Problem Description
统计给定文本文件中汉字的个数。
 

 

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

 

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

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

 

 

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

 

Sample Output
14
9
     长知识了,我只知道汉字占两字节,想靠汉字的字节数来判断,行不通,原来 汉字的ASCLL码是负的啊(一个汉字占两字节,所以会出现两次负号)。
        
技术分享图片
 1 #include<iostream>
 2 #include<iomanip>
 3 //#include<bits/stdc++.h>
 4 #include<cstdio>
 5 #include<cmath>
 6 #include<cstring>
 7 #include<sstream>
 8 #include<algorithm>
 9 #define PI  3.14159265358979
10 #define LL long long
11 #define  eps   0.00000001
12 #define LL long long
13 using namespace std;
14 int main()
15 {
16     char c[1000];
17     int T;
18     cin>>T;
19     getchar();
20     while(T--)
21     {
22         gets(c);
23         int sum=0;
24         int L=strlen(c);
25         for(int i=0;i<L;++i)
26         {
27             if(int(c[i])<0) ++sum;
28 
29         }
30         cout<<sum/2<<endl;
31     }
32 }
View Code

 

汉字统计

原文:https://www.cnblogs.com/Auroras/p/10800798.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!