• (注意格式,代替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);
            }
        }
    }
  • 相关阅读:
    three.js模型
    three.js贴图
    three.js材质
    three.js自定义形状
    border
    虚拟主机Dede程序安装
    万网虚拟主机目录
    ConcurrentHashMap
    Oracle中select使用别名
    单例模式
  • 原文地址:https://www.cnblogs.com/Weixu-Liu/p/9165579.html
Copyright © 2020-2023  润新知