887A. Div. 64#模特的数学技巧(字符串处理)

问题出处:http://codeforces.com/problemset/problem/887/A

问题大意:对于给出的一串二进制数,能否通过去掉一些数字,使之成为十进制下64的倍数

#include<iostream>
#include<algorithm>
using namespace std;
//题目表述的删除,而不是把1换成0 
int main(){
    string s;
    cin>>s;
    //不考虑第6位的高位数
    //对string类 find函数的使用 
    int p = s.find('1');
    cout<< (p!=string::npos && count(s.begin()+p,s.end(),'0') >= 6? "yes":"no");
    //对#include<algorithm>count函数使用 
    return 0;
}

二进制下,1000000前再加几个1或者0都表示64的倍数,所以只要保证某个1后面能够有6个“0”即可满足条件

本题数字串长度超过100比如要用字符串记录

本题使用了string类find函数、#include<algorithm>中的count函数

个人分享,欢迎指导,未经允许,请勿转载。谢谢!
原文地址:https://www.cnblogs.com/hello-OK/p/8052396.html