zoukankan      html  css  js  c++  java
  • HDU

    Time limit
    1000 ms
    Memory limit
    32768 kB

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

    Input
    输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本。
    Output
    对于每一段文本,输出其中的汉字的个数,每个测试实例的输出占一行。

    Sample Input

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

    Sample Output

    14
    9
    

    思路:
    ASCII码表范围0——127。汉字肯定不在里头。
    代码:

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <cstring>
    
    using namespace std;
    
    char board[1000];
    
    int main(){
        int N;
        cin>>N;
        getchar();
        while(N--){
            gets(board);
            int len = strlen(board);
            int sum = 0;
            for(int i=0 ; i<len ; i++){
                if(board[i]>=0 && board[i]<=127)sum++;
            }
            printf("%d
    ",(len-sum)/2);
        }
        return 0;
    }
  • 相关阅读:
    郑码
    AutoCAD 安装
    China Mobile 移动
    CCB 建行
    Word基础
    Java 继承
    Java 封装(内部类)
    Java 类与对象
    Java 方法
    Java 数组
  • 原文地址:https://www.cnblogs.com/vocaloid01/p/9514251.html
Copyright © 2011-2022 走看看