PS :在第一次模拟这场比赛时,看到很多人做这个题就去做这个题,没想到竟然没有看懂题意,还是很菜啊QAQ
题意分析:给定一个N,有N个数,每个数的二进制,每8位数为一个字节,97的进行比较,判断有多少个字节等于97?
模拟
/*************************************************************************
> File Name: J.cpp
> Author: ccdxc
> Mail: linyi0430@gmail.com
> Created Time: 2018年11月18日 星期日 13时00分57秒
************************************************************************/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n , ans;
string s = "10000110";
int judge(int a){
int t = 0;
string s1 = "";
while(a){
if(a % 2){
s1 += "1";
}
else s1 += "0";
a/=2;
}
int k = log2(s1.size());
if(k * k != s1.size()){
k++;
int num = 1 << k ;
for(int i = s1.size();i < num;i++)
s1 += "0";
}
for(int i = 0;i < s1.size() - 7;i+=8){
string s2 = s1.substr(i , 8);
//cout << s2 <<endl;
if(s == s2){
t++;
}
}
return t;
}
int main(){
//freopen("input.in","r",stdin);
//freopen("test.out","w" ,stdout);
int a;
while(scanf("%d",&n) == 1 && n){
ans = 0;
for(int i = 1;i <= n;i++){
cin >> a;
if(a < 97) continue;
else if(a == 97) ans++;
else ans += judge(a);
}
cout << ans << endl;
}
return 0;
}
二进制
/*************************************************************************
> File Name: ACJ.cpp
> Author: ccdxc
> Mail: linyi0430@gmail.com
> Created Time: 2018年11月19日 星期一 23时31分33秒
************************************************************************/
#include<bits/stdc++.h>
using namespace std;
int n , a;
int main(){
while(~scanf("%d",&n)){
int ans = 0;
while(n--){
scanf("%d",&a);
if(a < 97) continue;
else
while(a){
if(a % 256 == 97) ans++;
a >>= 8;
//cout << a<<endl;
}
}
cout << ans <<endl;
}
}