zoukankan      html  css  js  c++  java
  • (注意格式,代替C++的getchar())汉字统计hdu2030

    汉字统计

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

    Total Submission(s): 53302    Accepted Submission(s): 28875

    Problem Description

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

    Input

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

    Output

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

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

    Sample Input

    2

    WaHaHa! WaHaHa! 今年过节不说话要说只说普通话WaHaHa! WaHaHa!

    马上就要期末考试了Are you ready?

    Sample Output

    14

    9

    import java.util.Scanner;
    public class Main {
    
        public static void main(String[] args) {
            Scanner in =new Scanner (System.in);
            int n = in.nextInt();
            in.nextLine();         //代替C++的getchar();
            while(n-->0) {
                String a;
                a=in.nextLine();
                byte b[]=a.getBytes();   //转换为字节数组。
                int m=0;
                for(int i=0;i<b.length;i++) {
                    if(b[i]<0)
                        m++;
                }
                System.out.println(m/2);
            }
        }
    }
    
    import java.util.Scanner;
    public class Main {
    
        public static void main(String[] args) {
            Scanner in =new Scanner (System.in);
            int n = in.nextInt();
            in.nextLine();
            while(n-->0) {
                String a;
                a=in.nextLine();
                byte b[]=a.getBytes();
                int m=0;
                for(int i=0;i<b.length;i++) {            //也可以过。
                    if(b[i]<0||b[i]>255)
                        m++;
                }
                System.out.println(m/2);
            }
        }
    }
  • 相关阅读:
    Linux 下判断磁盘是ssd还是hdd
    Ceph rgw COR测试
    nfs 挂载选项
    【Linux命令】dmsetup--device mapper 管理工具(更底层的管理工具)
    Device Mapper 存储介绍
    easyui combotree 默认 初始化时就选中
    EasyUI 添加tab页(iframe方式)(转)
    EasyUI DataGrid 配置参数
    EasyUI 后台接受DataGrid传来的参数
    (转)combogrid的代码实例
  • 原文地址:https://www.cnblogs.com/Weixu-Liu/p/9165579.html
Copyright © 2011-2022 走看看