Find Small A
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 825 Accepted Submission(s): 411
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
首先asc2码是8bits的,所以我们要以8bits为一个单位在给出的数字中找‘a’,用了两种方法,一种是进制转换成二进制来做,这样显然太麻烦了,按照位运算来做就简单多了
////
//// main.cpp
//// Find Small A
////
//// Created by 张嘉韬 on 2017/3/19.
//// Copyright © 2017年 张嘉韬. All rights reserved.
////
//
//#include <iostream>
//#include <cstring>
//#include <cstdio>
//using namespace std;
//typedef long long ll;
//const int MAXN=32+10;
//const char OR[9]="10000110";
//char a[MAXN];
//int len;
//void tran(ll temp)
//{
// len=0;
// for(int i=0;i<=MAXN;i++) a[i]='0';
// while(temp!=0)
// {
// a[len++]=temp%2+'0';
// temp=temp/2;
// }
//}
//ll match()
//{
// ll cnt=0;
// for(int i=0;i<len;i+=8)
// {
// int flag=1;
// for(int j=0;j<8;j++)
// {
// if(OR[j]!=a[i+j])
// {
// flag=0;
// break;
// }
// }
// if(flag) cnt++;
// }
// return cnt;
//}
//ll match(ll temp)
//{
// ll cnt=0;
//
// return cnt;
//}
//int main(int argc, const char * argv[]) {
// //freopen("/Users/zhangjiatao/Desktop/input.txt","r",stdin);
// int n;
// while(scanf("%d",&n)!=EOF)
// {
// ll counter=0;
// for(int i=1;i<=n;i++)
// {
// ll temp;
// scanf("%lld",&temp);
// tran(temp);
// ll cnt=match();
// counter+=cnt;
// }
// printf("%lld\n",counter);
// }
// return 0;
//}
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main()
{
//freopen("/Users/zhangjiatao/Desktop/input.txt","r",stdin);
int n;
while(scanf("%d",&n)!=EOF)
{
long long cnt=0;
int m=pow(2,8)-1;
for(int i=1;i<=n;i++)
{
long long a;
scanf("%lld",&a);
for(int i=0;i<4;i++)
{
long long temp=a;
int k=i*8;
temp=temp>>k;
temp=temp&m;
if(temp==97) cnt++;
}
}
printf("%lld\n",cnt);
}
return 0;
}