頑張るだけ。
int no(char c)
{
if (c == 'I') return 1;
if (c == 'V') return 5;
if (c == 'X') return 10;
if (c == 'L') return 50;
if (c == 'C') return 100;
if (c == 'D') return 500;
if (c == 'M') return 1000;
return -1;
}
int conv(string s)
{
int sum = 0;
int i;
for (i = 0 ; i < (int)s.size() - 1; ++i) {
if (no(s[i + 1]) <= no(s[i])) sum += no(s[i]);
else {
sum += no(s[i + 1]) - no(s[i]);
++i;
}
}
if (i < s.size()) sum += no(s[i]);
return sum;
}
class KingSort {
public:
vector <string> getSortedList(vector <string> K)
{
vector< pair<string, pair<int, string> > > v;
for (int i = 0; i < K.size(); ++i) {
istringstream iss(K[i]);
string s, t;
iss >> s >> t;
int num = conv(t);
v.push_back(make_pair(s, make_pair(num, t)));
}
sort(v.begin(), v.end());
vector <string> ret;
for (int i = 0; i < v.size(); ++i) {
ret.push_back(v[i].first + " " + v[i].second.second);
}
return ret;
}
};
0 件のコメント :
コメントを投稿