Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  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:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator