Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Last active August 29, 2015 14:17
Show Gist options
  • Save henrybear327/1f2e913f75eb1d2e5604 to your computer and use it in GitHub Desktop.
Save henrybear327/1f2e913f75eb1d2e5604 to your computer and use it in GitHub Desktop.
lance w3a.c
#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