diff options
Diffstat (limited to '22.3/main.cpp')
-rw-r--r-- | 22.3/main.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/22.3/main.cpp b/22.3/main.cpp new file mode 100644 index 0000000..c648d84 --- /dev/null +++ b/22.3/main.cpp @@ -0,0 +1,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; +} |