HDU 5980 Find Small A(寻找小A)

HDU 5980 Find Small A(寻找小A)

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

 

Problem Description - 题目描述
As is known to all,the ASCII of character 'a' is 97. Now,find out how many character 'a' in a group of given numbers. Please note that the numbers here are given by 32 bits’ integers in the computer.That means,1digit represents 4 characters(one character is represented by 8 bits’ binary digits).
众所周知,字符 'a' 的ASCII码为97.现在,找出给定数组中出现了多少次 'a' 。注意,此处的数字为计算机中的32位整数。这表示,1个数字由四个字符组成(一个字符由8位二进制数组成)。
CN

 

Input - 输入
The input contains a set of test data.The first number is one positive integer N (1≤N≤100),and then N positive integers ai (1≤ ai≤2^32 - 1) follow.
只有一组输入数据。第一个数为一个正整数N (1≤N≤100),随后有N个正整数ai (1≤ ai≤2^32 - 1)。
CN


Output - 输出

Output one line,including an integer representing the number of 'a' in the group of given numbers.
输出一行一个整数,表示数组中 'a' 出现的次数。
CN

 

Sample Input - 输入样例

3
97 24929 100

 

Sample Output - 输出样例

3

 

题解

  水题。
  一个数可以拆成4个字符,判断这4个字符是不是’a’,统计一下即可。
  刚开始被括内的二进制解释误导了,还以为要从二进制下一位一位地寻找匹配,信手一发KMP直接翻车……

 

代码 C++

 1 #include<cstdio>
 2 int main(){
 3     int t, i, opt = 0;
 4     unsigned int a;
 5     scanf("%d", &t);
 6     while (t--){
 7         for (i = scanf("%u", &a); i < 5; ++i){
 8             if ((a & 0xFF) == 'a') ++opt;
 9             a >>= 8;
10         }
11     }
12     printf("%d\n", opt);
13     return 0;
14 }


 

 

转载于:https://www.cnblogs.com/Simon-X/p/6044496.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值