Last active
August 29, 2015 14:17
-
-
Save henrybear327/1f2e913f75eb1d2e5604 to your computer and use it in GitHub Desktop.
lance w3a.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#define SIZE 18 | |
int power(int A,int p); | |
int main() | |
{ | |
int cases; | |
while(scanf("%d",&cases) && cases!=0) { | |
int result=0; | |
getchar(); | |
while(cases--) { | |
char bin[SIZE]= {'0'}; | |
fgets(bin,SIZE,stdin); | |
int i,len = strlen(bin) - 1; | |
int p=len-1; | |
for(i=0; i<len; i++) { | |
result+=(bin[i]-'0')*power(2,p); | |
p--; | |
} | |
} | |
printf("%d\n",result); | |
} | |
return 0; | |
} | |
int power(int A,int p) //correct | |
{ | |
int r=1,i; | |
for(i=1; i<=p; i++) { | |
r=r*A; | |
} | |
return r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment