汉字统计

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);
}
}
}

(注意格式,代替C++的getchar())汉字统计hdu2030的更多相关文章

  1. HDOJ2030汉字统计

    汉字统计 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  2. 杭电ACM 汉字统计

    汉字统计 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  3. HDU 2030 汉字统计(汉字Asics码为负,占两个char)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2030 汉字统计 Time Limit: 2000/1000 MS (Java/Others)    M ...

  4. HDU 2027 汉字统计

    汉字统计 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  5. hdu:2030.汉字统计

    Problem Description 统计给定文本文件中汉字的个数.   Input 输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本.   Output 对于每一段文本,输出其中的汉 ...

  6. HDU 2030 汉字统计

    http://acm.hdu.edu.cn/showproblem.php?pid=2030 Problem Description 统计给定文本文件中汉字的个数.   Input 输入文件首先包含一 ...

  7. 题解报告:hdu 2030 汉字统计

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2030 Problem Description 统计给定文本文件中汉字的个数. Input 输入文件首先 ...

  8. hdu2030 汉字统计

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2030 解题思路:主要考察汉字的编码方式, 汉字机内码在计算机的表达方式的描述是,使用二个字节,汉字的每 ...

  9. HDOJ 2030 汉字统计

    Problem Description 统计给定文本文件中汉字的个数. Input 输入文件首先包含一个整数n,表示测试实例的个数,然后是n段文本. Output 对于每一段文本,输出其中的汉字的个数 ...

随机推荐

  1. 回溯法解n皇后问题

    #include<bits/stdc++.h> using namespace std; int n,sum; int c[100]; void search(int cur){ if(c ...

  2. Individual P1: Preparation

    Individual Project - Word frequency program tally the frequency of words under a directory (2 modes) ...

  3. 《Linux内核分析》第六周学习总结

    <Linux内核分析>第六周学习总结                         ——进程的描述和进程的创建 姓名:王玮怡  学号:20135116 一.理论部分 (一)进程的描述 1 ...

  4. Opentsdb 启动显示配置文件不存在

    今天 重新启动opentsdb  出现本地配置文件不存在   这不知道  我查了一下官网 了解到 You can use the --config command line argument to s ...

  5. 小学生四则运算APP核心代码公布

    Mainactivity类: package com.example.XXSCYS; import java.io.ByteArrayOutputStream; import java.io.File ...

  6. Windows系统下PHP使用Redis

    参考链接:https://www.cnblogs.com/lhat/p/6402472.html 环境:windows 10  64位操作系统    php 5.4 redis 3.0 1.redis ...

  7. centos7 修改网络配置问题

    ip adr 查看ip 查看报错详细信息 journalctl -xe 查看网络故障命令 cat /var/log/messages |grep network 报错现象 Error: Connect ...

  8. .NET中的许可证机制--License

    .NET中的许可证机制主要类:System.ComponentModel.License(为所有许可证提供 abstract 基类.向组件的特定实例授予许可证)     System.Componen ...

  9. python数据统计量分析

    #-*- coding: utf-8 -*- #餐饮销量数据统计量分析 from __future__ import print_function import pandas as pd cateri ...

  10. codeforces469B

    Chat Online CodeForces - 469B 问题描述 你和你的朋友经常在网上聊天.你的朋友作息规律每天只会在p个时间段[ai,bi]在线.你作息混乱,假设你在t时刻起床,那么你会在q个 ...