湖北民族學院 OJ HBMY 2093: 二進位制數轉換為十進位制數
阿新 • • 發佈:2018-11-10
2017級 電腦科學與技術 袁壯苗
題目描述
題目很簡單,就是把一個二進位制數轉換為十進位制數,然後輸出。
輸入描述
多組測試資料,第一行一個正整數 n (n<=1000),表示後面有 n 組測試資料,每組一行。
接下來有 n 行,每行為一個不超過32位的二進位制數。
輸出描述
對每組測試資料,在一行中輸出對應的十進位制數。
輸入樣例
2 0111 1111輸出樣例
7 15來源or型別
#include<stdio.h> #include<string.h> #include<math.h> int main() { char a[100]; long long int i,n,len,temp; long long int sum; int j; scanf("%lld",&n); getchar(); while(n--) { sum=0; temp=0; j=0; gets(a); len=strlen(a); for(i=len-1;i>=0;i--) { temp=a[i]-48; sum+=temp*(int)pow(2,j); j++; } printf("%lld\n",sum); } }