Skip to content

Instantly share code, notes, and snippets.

@henrybear327
Created March 9, 2018 02:56
Show Gist options
  • Save henrybear327/6280d339c375a0b8e2c090db66707fe0 to your computer and use it in GitHub Desktop.
Save henrybear327/6280d339c375a0b8e2c090db66707fe0 to your computer and use it in GitHub Desktop.
simulation_Binary.c
#include <stdio.h>
#include <string.h>
void solve(int n)
{
long long int ans = 0;
for (int i = 0; i < n; i++) {
char inp[100];
scanf("%s", inp);
int len = strlen(inp);
long long int num = 0;
for (int j = len - 1; j >= 0; j--) {
if (inp[j] == '1')
num |= (1 << (len - 1 - j));
}
ans += num;
}
printf("%lld\n", ans);
}
int main()
{
int n;
while (scanf("%d", &n) == 1 && n)
solve(n);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment