Find Small A
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1680 Accepted Submission(s): 826
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
给你n个十进制的数,让你把它变成2进制,然后每8位算一下是不是等于97,是就ans++。
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <queue>
#include <math.h>
#include <vector>
using namespace std;
const int maxn = 55;
int a[maxn];
int ans;
int num=0;
void er(int x)
{
num=0;
while(x){
num++;
a[num]=x%2;
x=x/2;
}
}
int main()
{
int n;
while(~scanf("%d",&n)){
ans=0;
for(int i=1;i<=n;i++){
int p;scanf("%d",&p);
er(p);
int cnt=0;
int now=0;
for(int j=1;j<=num;j++){
cnt++;
if(a[j]){
now+=1<<(cnt-1);
}
if(cnt==8){
if(now==97){
ans++;
}
now=0;
cnt=0;
}
}
if(now==97){
ans++;
}
}
printf("%d\n",ans);
}
}