Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@kokosabu
Created June 8, 2014 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kokosabu/4aa94c944c3dfb28786f to your computer and use it in GitHub Desktop.
Save kokosabu/4aa94c944c3dfb28786f to your computer and use it in GitHub Desktop.
#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