/****************************
* 2012/06/23 *
* AOJ1137 Numeral System *
* crane *
*****************************/
#include<iostream>
#include<string>
using namespace std;
char c[4] = {'m', 'c', 'x', 'i'};
int v[4] = {1000, 100, 10, 1};
int toint(string str);
int main(){
int N=0;
cin >> N;
string in1,in2;
while(N--){
cin >> in1 >> in2;
int sum = toint(in1) + toint(in2); //合計計算
for(int i=0; i<4; i++){
int d = 0;
while(sum >= v[i]){
sum-= v[i];
d++;
}
if(d > 1) cout << d;
if(d > 0) cout << c[i];
}
cout << endl;
}
return 0;
}
int toint(string str){
int result = 0;
int d=1;
for(int i=0; i<str.size(); i++){
if('0' <= str[i] && str[i] <= '9')
d = str[i] - '0';
else{
for(int j=0; j<4; j++){
if(str[i] != c[j]){ continue;}
result += v[j] * d;
d = 1;
break;
}
}
}
return result;
}
0 件のコメント:
コメントを投稿