blob: c648d84a45de8752d8f4dac08e0f935d3323a5a0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <iostream>
#include <string>
using namespace std;
int
getPriority(char c)
{
// [1;52]
if ('a' <= c && c <= 'z') return c - 'a' + 1;
if ('A' <= c && c <= 'Z') return c - 'A' + 27;
throw "unexpected input";
}
int
main()
{
long total = 0;
for (string line; getline(cin, line); ) {
bool inFirstHalf[52] = {0};
if (line.length() % 2 != 0) throw "unexpected input";
int found = -1;
for (int i = 0; i < line.length(); i++) {
int p = getPriority(line[i]);
if (i < line.length() / 2) {
inFirstHalf[p-1] = true;
} else {
if (inFirstHalf[p-1]) {
found = p;
break;
}
}
}
if (found == -1) throw "bad input";
total += found;
}
cout << total << endl;
}
|