2105 IP Address

#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
 

      int n;
       scanf("%d",&n);
       int a[80],b[80],c[80],d[80];
       char str[200];
       while(n--)
       {
            memset(a,0,sizeof(a));
             memset(b,0,sizeof(b));
                memset(c,0,sizeof(c));
                  memset(d,0,sizeof(d));
                 memset(str,0,sizeof(str));
             scanf("%s",str);
            int i,j,t1=0,t2=0,t3=0,t4=0;
           for(j=0;j<8;j++)
            {
                a[j]=str[j]-'0';
                if(a[j]==1)
                {
                    t4+=(int)pow(2,7-j);
                }
            }
           for(j=8;j<16;j++)
            {
                b[j]=str[j]-'0';
                if(b[j]==1)
                {
                    t3+=(int)pow(2,15-j);
                }
            }
            for(j=16;j<24;j++)
            {
                c[j]=str[j]-'0';
                if(c[j]==1)
                {
                    t2+=(int)pow(2,23-j);
                }
            }
            for(j=24;j<32;j++)
            {
                d[j]=str[j]-'0';
                if(d[j]==1)
                {
                    t1+=(int)pow(2,31-j);
                }
            }
           printf("%d%c%d%c%d%c%d",t4,'.',t3,'.',t2,'.',t1);
           printf("\n");
       }
       return 0;
}
posted @ 2013-07-27 11:01  清风旋叶  阅读(199)  评论(0编辑  收藏  举报