SRM 160 DIV2 Level One
C++のfindってメンドイ。
数字を覚えるのに、1〜0までで"TRADINGFEW"とかテーブルを作っておいて、"LGXWEV"で709とする。という変な暗記法。暗号として使ったほうが効果的だと思う。
#include <string> #include <algorithm> using namespace std; template <class T, class U> int find_index(T seq, U value) { typeof (seq.begin()) res = find(seq.begin(), seq.end(), value); return (res != seq.end()) ? (res - seq.begin()) / sizeof (U) : -1; } class Substitute { public: static int getValue(string key, string code) { int k = 1; int sum = 0; for (int i = code.length() - 1; i >= 0; i--) { int index = find_index(key, code[i]); if (index != -1) { sum += (index + 1) % 10 * k; k *= 10; } } return sum; } };
いろんな所にイテレータが出てくるな。