简单题
View Code
#include#include #include #include using namespace std; #define maxl 20 char st1[maxl], st2[maxl]; int getd(char *st, char a) { int len = strlen(st); int x = -1; for (int i = 0; i < len; i++) if (st[i] == a) { x = i; break; } if (x == -1) return 0; if (x == 0 || st[x - 1] > '9' || st[x - 1] < '0') return 1; return st[x - 1] - '0'; } int cal(char *st) { int ans = 0; ans += getd(st, 'm') * 1000; ans += getd(st, 'c') * 100; ans += getd(st, 'x') * 10; ans += getd(st, 'i'); return ans; } void print(int a) { int b = a / 1000; if (b > 1) putchar('0' + b); if (b != 0) putchar('m'); b = a / 100 % 10; if (b > 1) putchar('0' + b); if (b != 0) putchar('c'); b = a / 10 % 10; if (b > 1) putchar('0' + b); if (b != 0) putchar('x'); b = a % 10; if (b > 1) putchar('0' + b); if (b != 0) putchar('i'); putchar('\n'); } int main() { //freopen("t.txt", "r", stdin); int t; scanf("%d", &t); while (t--) { scanf("%s%s", st1, st2); int a = cal(st1); int b = cal(st2); print(a + b); } return 0; }