Find Small A
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 349 Accepted Submission(s): 175
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).
Input
The input contains a set of test data.The first number is one positive integer N (1≤N≤100),and then N positive integersai (1≤
ai
≤2^32 - 1) follow
Output
Output 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
Source
Recommend
题意:给出一个32位进制的数字,把分为8进制的数字,求有一个97
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[100];
int main()
{
int n,m,i,j,k;
while(scanf("%d",&n)!=EOF)
{
int sum=0;
while(n--)
{
scanf("%d",&m);
memset(a,0,sizeof(a));
k=0;
while(m)
{
a[k++]=m%2;
m=m/2;
}
for(i=0;i<k;i=i+8)
{
int ans=0;
int q=1;
for(j=i;j<i+8;j++)
{
ans+=q*a[j];
q=q*2;
}
if(ans==97)
sum++;
ans=0;
}
}
printf("%d\n",sum);
}
return 0;
}