标签:des style blog io color ar os sp for
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 const int maxn=100000+10; 5 char h[maxn],b[4*maxn],e[4*maxn]; 6 int main() 7 { 8 int n; 9 scanf("%d",&n); 10 while(n--) 11 { 12 scanf("%s",h); 13 int len=0; 14 for(int i=strlen(h)-1;i>=0;i--)//十六转二 15 { 16 int x; 17 if(h[i]>=‘0‘&&h[i]<=‘9‘) 18 x=h[i]-‘0‘; 19 else 20 { 21 x=h[i]-‘A‘+10; 22 } 23 for(int j=0;j<4;j++) 24 { 25 e[len++]=x%2+‘0‘; 26 x/=2; 27 } 28 } 29 e[len]=‘\0‘; 30 int cnt=1,x=0,l=0; 31 for(int i=0;i<len;i++)//二转八 32 { 33 if(cnt==4||i==len-1) 34 { 35 x+=cnt*(e[i]-‘0‘); 36 cnt=1; 37 b[l++]=x+‘0‘; 38 x=0; 39 } 40 else 41 { 42 x+=cnt*(e[i]-‘0‘); 43 cnt*=2; 44 } 45 } 46 int i=l-1; 47 while(i>=0&&b[i]==‘0‘)//去前导0 48 i--; 49 if(i<0) 50 printf("0\n"); 51 for(;i>=0;i--) 52 { 53 printf("%c",b[i]); 54 } 55 printf("\n"); 56 } 57 return 0; 58 }
标签:des style blog io color ar os sp for
原文地址:http://www.cnblogs.com/wpnan/p/4095730.html