码迷,mamicode.com
首页 > 其他好文 > 详细

HDU5980

时间:2017-05-13 23:15:09      阅读:195      评论:0      收藏:0      [点我收藏+]

标签:set   test   integer   msu   names   inpu   output   ane   ssi   

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

标签:set   test   integer   msu   names   inpu   output   ane   ssi   

原文地址:http://www.cnblogs.com/--lr/p/6850523.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!