Skip to content

Instantly share code, notes, and snippets.

@kokosabu kokosabu/B002.c
Created Jun 8, 2014

Embed
What would you like to do?
#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
You can’t perform that action at this time.