Created
June 8, 2014 12:51
-
-
Save kokosabu/4aa94c944c3dfb28786f to your computer and use it in GitHub Desktop.
This file contains 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> | |
// 定数 | |
enum { | |
N = 26, | |
}; | |
int main() | |
{ | |
int resistances[N]; | |
char alphabets[N]; | |
long long answer; | |
int n; | |
int i; | |
char alphabet; | |
int resistance; | |
int len; | |
double tmp; | |
scanf("%d\n", &n); | |
for (i = 0; i < n; i++) { | |
scanf("%c %d\n", &alphabet, &resistance); | |
resistances[alphabet - 'A'] = resistance; | |
} | |
answer = 0; | |
while (scanf("%s", alphabets) != EOF) { | |
len = strlen(alphabets); | |
if (len == 1) { | |
answer += resistances[alphabets[0] - 'A']; | |
} else { | |
tmp = 0.0; | |
for (i = 0; i < len; i++) { | |
tmp += (double)1.0 / (double)resistances[alphabets[i] - 'A']; | |
} | |
answer += (long long)( (double)1.0 / tmp ); | |
} | |
} | |
printf("%lld\n", answer); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment