Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
Register

## 谁能告诉我哪里错了啊？测试数据能过，谢谢...

Posted by I_am_Legend at 2009-09-04 09:10:35 on Problem 2685
```#include <iostream>
#include <string>
using namespace std;

int fun(char ch) {
switch(ch) {
case 'm':
return 1000;
case 'c':
return 100;
case 'x':
return 10;
case 'i':
return 1;
}
}

int fun1(string str) {
int sum = 0;
for (int i = 0; i < str.length(); i++)
if (str[i] > '1' && str[i] <= '9')
sum += (str[i] - '0') * fun(str[++i]);
else
sum += fun(str[i]);
return sum;
}

void fun2(int num) {
string str;
int tmp;

tmp = num % 10;
if (tmp) {
str.append("i");
if (tmp - 1) {
char buf[10];
_itoa(tmp, buf, 10);
str.append(string(buf));
}
}

num /= 10;
tmp = num % 10;
if (tmp) {
str.append("x");
if (tmp - 1) {
char buf[10];
_itoa(tmp, buf, 10);
str.append(string(buf));
}
}

num /= 10;
tmp = num % 10;
if (tmp) {
str.append("c");
if (tmp - 1) {
char buf[10];
_itoa(tmp, buf, 10);
str.append(string(buf));
}
}

num /= 10;
tmp = num % 10;
if (tmp) {
str.append("m");
if (tmp - 1) {
char buf[10];
_itoa(tmp, buf, 10);
str.append(string(buf));
}
}

for (int i = str.length() - 1; i >= 0; i--)
cout << str[i];
cout << endl;
}

int main() {
int n;
string a, b;

cin >> n;
while (n--) {
cin >> a;
cin >> b;
fun2(fun1(a) + fun1(b));
}

return 0;
}```

Followed by: