void test_bin_express()
{
assert( Bin("0000")==0 );
assert( Bin("1 0000")==16 );
}
#include <math.h>
#include <stdlib.h>
#include <string.h>
static int Calc(int val)
{
if(val<10)
{
return val;
}
else
{
return (Calc(val/10)<<1)+(Calc(val%10));
}
}
static int IsNum(const char *c)
{
if( *c<='9' && *c>='0' )
{
return 1;
}
else
{
return 0;
}
}
static void Compact(char *dst,const char *src)
{
int i = 0;
int valid = 0;
while( i<strlen(src) )
{
if( IsNum(src+i) )
{
dst[valid++] = src[i++];
}
else
{
i++;
}
}
}
int Bin(char *s)
{
char compact[40] = {0};
int val = 0;
Compact(compact,s);
val = atoi(compact);
return Calc(val);
}