首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >HDOJ 2030 汉字统计

HDOJ 2030 汉字统计

作者头像
谙忆
发布2021-01-20 16:14:00
发布2021-01-20 16:14:00
9820
举报
文章被收录于专栏:程序编程之旅程序编程之旅

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

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

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

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

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

Sample Output 14 9

代码语言:javascript
复制
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.next();
        while(n-->0){
            int m=0;
            String strs = sc.nextLine();
            char[] strc = new char[strs.length()];
            strc = strs.toCharArray();
            for(int i=0;i<strc.length;i++){
                if(strc[i]>128){
                    m++;
                }
            }
            System.out.println(m);
        }
    }
}    
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016/01/22 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档