HDU 5980 Find Small A

来源:互联网 发布:北京洪浪网络诈骗案 编辑:程序博客网 时间:2024/06/06 11:42

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
397 24929 100
 

Sample Output
3
 

Source
2016ACM/ICPC亚洲区大连站-重现赛(感谢大连海事大学)
 

Recommend
wange2014   |   We have carefully selected several similar problems for you:  5981 5979 5977 5976 5975 
题意:给出一个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;}


0 0
原创粉丝点击