输入的字符串8个一组,把二进制数转化为十进制,输出。
单case、多case都能过
代码:

Source Code

Problem: 2105 User: wic
Memory: 264K Time: 0MS
Language: C++ Result: Accepted
  • Source Code
    #include<iostream>
        #include<cstring>
        using namespace std;
        int v[9]={0,1,2,4,8,16,32,64,128};
        int main()
        {
        int n,i,j,m,k;
        char a[35];
        int ans[4];
        cin>>n;
        for(i=0; i<n; i++){
        cin>>a;
        memset(ans, 0, sizeof(ans));
        int l=strlen(a);k=0;m=0;
        for(j=l-1; j>=0; j--){
        k++;
        ans[m]+=(a[j]-'0')*v[k];
        if(k==8)
        k=0,m++;
        }
        cout<<ans[3]<<"."<<ans[2]<<"."<<ans[1]<<"."<<ans[0]<<endl;
        }
        return 0;
        }