#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
map<char, int> val;
val['B'] = 1;
val['U'] = 10;
val['S'] = 100;
val['P'] = 1000;
val['F'] = 10000;
val['T'] = 100000;
val['M'] = 1000000;
int cases;
for (cin >> cases; cases; cases--) {
string line;
cin >> line;
bool is_order_increasing, order_set = false, error = false;
int n = line.length(), consecutive_same_value = 1, total_val = 0;
if (n > 0) {
total_val = val[line[0]];
for (int i = 1; i < n; i++) {
char ch = line[i];
total_val += val[ch];
if (val[ch] != val[line[i - 1]]) {
if (order_set) {
if (is_order_increasing != (val[line[i - 1]] < val[ch])) {
error = true;
break;
}
} else {
order_set = true;
is_order_increasing = val[line[i - 1]] < val[ch];
}
consecutive_same_value = 1;
}
else {
consecutive_same_value++;
if (consecutive_same_value == 10) {
error = true;
break;
}
}
}
}
if (error)
cout << "error" << endl;
else
cout << total_val << endl;
}
return 0;
}
Thursday, April 23, 2015
UVa 11787 - Numeral Hieroglyphs
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment