zoukankan      html  css  js  c++  java
  • HDU 5980 Find Small A(寻找小A)

    HDU 5980 Find Small A(寻找小A)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)

     

    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).
    众所周知,字符 'a' 的ASCII码为97.现在,找出给定数组中出现了多少次 'a' 。注意,此处的数字为计算机中的32位整数。这表示,1个数字由四个字符组成(一个字符由8位二进制数组成)。
    CN
    Input - 输入
    The input contains a set of test data.The first number is one positive integer N (1≤N≤100),and then N positive integers ai (1≤ ai≤2^32 - 1) follow.
    只有一组输入数据。第一个数为一个正整数N (1≤N≤100),随后有N个正整数ai (1≤ ai≤2^32 - 1)。
    CN


    Output - 输出

    Output one line,including an integer representing the number of 'a' in the group of given numbers.
    输出一行一个整数,表示数组中 'a' 出现的次数。
    CN

    Sample Input - 输入样例

    3
    97 24929 100
    

     

    Sample Output - 输出样例

    3
    

     

    题解

      水题。
      一个数可以拆成4个字符,判断这4个字符是不是’a’,统计一下即可。
      刚开始被括内的二进制解释误导了,还以为要从二进制下一位一位地寻找匹配,信手一发KMP直接翻车……

     

    代码 C++

     1 #include<cstdio>
     2 int main(){
     3     int t, i, opt = 0;
     4     unsigned int a;
     5     scanf("%d", &t);
     6     while (t--){
     7         for (i = scanf("%u", &a); i < 5; ++i){
     8             if ((a & 0xFF) == 'a') ++opt;
     9             a >>= 8;
    10         }
    11     }
    12     printf("%d
    ", opt);
    13     return 0;
    14 }


     

  • 相关阅读:
    sharepoint2013搜索
    jquery文档
    jquery 修改样式
    文本区使用
    jquery重置
    jquery 获取某a标签的href地址 实现页面加载时跳转
    js学习
    《当裸辞的程序猿遇上最冷季九》——累觉不爱,暂时停更
    《当裸辞的程序猿遇上最冷季八》——第一次约女孩吃饭
    《当裸辞的程序猿遇上最冷季七》—国庆回家
  • 原文地址:https://www.cnblogs.com/Simon-X/p/6044496.html
Copyright © 2011-2022 走看看