1#include <iostream>2#include <cstdio>3#include <cstring>4#include <cstdlib>5 using namespacestd;6 7 Charstr[100010];8 inta[5000000];9 Ten intMain () One { A inti,k,j,n,l; -scanf"%d",&k); - while(k--) the { -scanf"%s", str); -L=strlen (str); -Memset (A,0,sizeof(a)); j=0; + for(i=l-1; i>=0; i--) - { + if(str[i]=='A') A { ata[j++]=0; a[j++]=1; a[j++]=0; a[j++]=1; - } - Else - if(str[i]=='B') { -a[j++]=1; a[j++]=1; a[j++]=0; a[j++]=1; -}Else in if(str[i]=='C') - { toa[j++]=0; a[j++]=0; a[j++]=1; a[j++]=1; +}Else - if(str[i]=='D') { thea[j++]=1; a[j++]=0; a[j++]=1; a[j++]=1; *}Else $ if(str[i]=='E')Panax Notoginseng { -a[j++]=0; a[j++]=1; a[j++]=1; a[j++]=1; the } + Else A if(str[i]=='F') the { +a[j++]=1; a[j++]=1; a[j++]=1; a[j++]=1; -}Else { $n=str[i]-'0'; $ intg=J; - while(n) - { thea[j++]=n%2; -n=n/2;Wuyi } thej=g+4; - } Wu - } About intE,d,h=0; $ for(i=0; i<j;i+=3) - { -D=1; n=0; - for(e=i;e<i+3;++e) { An+=a[e]*d;d*=2; + } thea[h++]=N; - } $ for(i=h-1; i>=0; i--) the if(a[i]!=0) Break; the for(j=i;j>=0; j--) theprintf"%d", A[j]); theprintf"\ n"); - } in return 0; the}View Code
Basic Exercise 16 Binary conversion octal