照著題目的過程做即可。
C++(0.008)
/*******************************************************/
/* UVa 11398 The Base-1 Number System */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2012/09/19 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
string baseone_num_part;
string basetwo_num = "";
int num;
char flag;
while( cin >> baseone_num_part && baseone_num_part != "~"){
if( baseone_num_part == "#" ){
num = 0;
for( int i = 0 ; i < basetwo_num.length() ; i++ ){
if( i ) num *= 2;
if( basetwo_num[i] == '1' ) num += 1;
}
basetwo_num = "";
printf( "%d\n", num );
}
else if( baseone_num_part.length() == 1 )
flag = '1';
else if( baseone_num_part.length() == 2 )
flag = '0';
else
for( int i = 0 ; i < baseone_num_part.length()-2 ; i++ )
basetwo_num += flag;
}
return 0;
}