HDU5980
Posted 不积跬步无以至千里,不积小流无以成江海
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU5980相关的知识,希望对你有一定的参考价值。
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).
InputThe input contains a set of test data.The first number is one positive integer N (1≤N≤100),and then N positive integersai (1≤ aiai≤2^32 - 1) followOutputOutput one line,including an integer representing the number of ‘a‘ in the group of given numbers.Sample Input
3
97 24929 100
Sample Output
3
题意:给N个数 每个数都可以拆开成一个32位的2进制 每八位一个字节 每个字节的2进制数换算成十进制的看有多少个97
思路:CillyB: % 256是看看后8位是多少, /= 256是去掉后8位
1 #include <iostream>
2 #include <cstdio>
3 using namespace std;
4
5 int main()
6 {
7 int ans,n,x;
8 int i;
9 cin>>n;
10 ans=0;
11 for(i=0;i<n;i++)
12 {
13 scanf("%d",&x);
14 while(x)
15 {
16 if(x%256==97)
17 {
18 ans++;
19 }
20 x/=256;
21 }
22 }
23 cout<<ans<<endl;
24 }
以上是关于HDU5980的主要内容,如果未能解决你的问题,请参考以下文章
HDU4057 Rescue the Rabbit(AC自动机+状压DP)