Created
March 9, 2018 02:56
-
-
Save henrybear327/6280d339c375a0b8e2c090db66707fe0 to your computer and use it in GitHub Desktop.
simulation_Binary.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 <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