#include <iostream>
#include <vector>
#include <cassert>
#include <string>
using namespace std;
/*help funkcija kojom iz unesenog
stringa punis bool kontejner */
bool toBool(const char& s)
{
assert(s == '0' || s == '1');
return s == '1';
}
class Covjece {
public:
Covjece( const vector<bool>& binary )
: m_binary(binary)
{ it = m_binary.begin();
cout<< endl << "rezultat : " << boolalpha << check() << endl;
}
bool check();
private:
const vector<bool>& m_binary;
vector<bool>::const_iterator it;
};
/* check() ti je core cijele operacije.
kako si postavio zadatak , navedeni
ima samo jedno true rijesenje :: iza n nula moraju slijediti do kraja samo
jedinice. prvi while chekira nule , drugi
jedinice. u svim ostalim situacijama dobivas false*/
bool Covjece::check()
{
if(*it == 1)
return false;
while( it != m_binary.end() )
{
if( *it == 0)
it++;
else
{
while( it != m_binary.end() )
{
if( *it == 1 )
it++;
else
return false;
}
return true;
}
}
}
int main()
{
vector<bool> binary;
string num;
cout<< "Pucaj binarni broj : ";
cin>> num;
for(string::reverse_iterator it = num.rbegin() ; it != num.rend() ; it++)
{
binary.push_back( toBool( *it ) );
}
/*odbaciti suvisnje prednje nule
u binarnom broju*/
while( *(binary.end() - 1) == 0 )
{
binary.erase( binary.end() - 1 );
}
cout<< endl << "Provjera za broj : ";
for(int i=binary.size()-1 ; i > -1 ; i--)
cout<< binary[ i ];
Covjece provjeri_ovaj_broj(binary);
return 0;
}