| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
谁能告诉我哪里错了啊?测试数据能过,谢谢...#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: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator