1 #include <iostream> 2 #include <string> 3 #define MAXN 26 4 5 using namespace std; 6 7 int _map[MAXN]; 8 9 string fun(int sum); 10 11 int main() 12 { 13 //freopen("acm.acm","r",stdin); 14 int test; 15 int i; 16 string s_1; 17 string s_2; 18 int sum_1; 19 int sum_2; 20 int sum; 21 _map['m'-'a'] = 1000; 22 _map['c'-'a'] = 100; 23 _map['x'-'a'] = 10; 24 _map['i'-'a'] = 1; 25 cin>>test; 26 while(test --) 27 { 28 cin>>s_1>>s_2; 29 sum_1 = 0; 30 sum_2 = 0; 31 for(i = 0; i < s_1.length(); ++ i) 32 { 33 34 if(s_1[i] >= '2' && s_1[i] <= '9') 35 { 36 ++ i; 37 sum_1 += (s_1[i-1]-'0')*_map[s_1[i]-'a']; 38 } 39 else 40 { 41 sum_1 += _map[s_1[i]-'a']; 42 } 43 } 44 for(i = 0; i < s_2.length(); ++ i) 45 { 46 if(s_2[i] >= '2' && s_2[i] <= '9') 47 { 48 ++ i; 49 sum_2 += (s_2[i-1]-'0')*_map[s_2[i]-'a']; 50 } 51 else 52 { 53 sum_2 += _map[s_2[i]-'a']; 54 } 55 } 56 //cout<<sum_1<<" "<<sum_2<<endl; 57 sum = sum_1 + sum_2; 58 cout<<fun(sum)<<endl; 59 } 60 } 61 62 string fun(int sum) 63 { 64 string s; 65 int num_m; 66 int num_c; 67 int num_x; 68 int num_i; 69 num_m = sum/1000; 70 sum %= 1000; 71 num_c = sum/100; 72 sum %= 100; 73 num_x = sum/10; 74 sum %= 10; 75 num_i = sum; 76 if(num_m != 0) 77 { 78 if(num_m == 1) 79 { 80 s += 'm'; 81 } 82 else 83 { 84 s += char(num_m + '0'); 85 s += 'm'; 86 } 87 } 88 if(num_c != 0) 89 { 90 if(num_c == 1) 91 { 92 s += 'c'; 93 } 94 else 95 { 96 s += char(num_c + '0'); 97 s += 'c'; 98 } 99 } 100 101 if(num_x != 0) 102 { 103 if(num_x == 1) 104 { 105 s += 'x'; 106 } 107 else 108 { 109 s += char(num_x + '0'); 110 s += 'x'; 111 } 112 } 113 114 if(num_i != 0) 115 { 116 if(num_i == 1) 117 { 118 s += 'i'; 119 } 120 else 121 { 122 s += char('0' + num_i); 123 s += 'i'; 124 } 125 } 126 return s; 127 }