Shortening codes

Problem hidden
This problem was hidden by Editorial Board member probably because it has incorrect language version or invalid test data, or description of the problem is not clear.

SPOJ Problem Set (main)

5671. Roman calculator

Problem code: ROMANCAL

Given string a and string b your task is to calculate sum, difference, product, quotient or remainder depending on given char c.

Input

The first line of the standard input contains one integer t (t<101) which is the number of test cases.

In each of the next t lines there are string a (I<=a<=V*M), char c ('+', '-', '*', ':' or '%') and string b (I<=b<=V*M).

Output

For each test, print sum if c='+', difference if c='-', product if c='*', quotient if c=':', remainder if c='%' or ERROR if the result equals 0. If the result is negative print '-' in front of it. The result will be integer.

Example

Input:
6
II + III
II - III
II * III
VI : III
V % III
I - I
Output:
V
-I
VI
II
II
ERROR


Added by:Piotr K±kol
Date:2009-12-23
Time limit:10s
Source limit:50000B
Languages:All
Resource:Roman numerals

hide comments
2011-02-08 20:04:50 Piotr K±kol
9000.
2011-02-07 05:08:12 hallvabo
What is the upper limit on the output string length?
2010-09-01 11:18:44 Piotr Fusik
Thank you.
2010-08-31 21:45:06 Piotr K±kol
For example:
MCDLXXIV % LVII
:-)
2010-08-31 21:10:07 Piotr Fusik
Okay, that was Perl 5.12 vs 5.10 incompatibility. How about 3984519 ?
2010-08-30 18:53:29 Piotr K±kol
Always, unfortunately. It always print ERROR. Here are real errors from Your program:
Number found where operator expected at (eval 1) line 1, near "0 0"
(Missing operator before 0?)
Number found where operator expected at (eval 2) line 1, near "00 00"
(Missing operator before 00?)
Number found where operator expected at (eval 3) line 1, near "000 000"
(Missing operator before 000?)
Number found where operator expected at (eval 4) line 1, near "0000 0000"
(Missing operator before 0000?)
etc.

Weird that You got WA, not NZEC or SIGSEGV.

Last edit: 2010-08-30 18:54:23
2010-08-30 16:44:18 Piotr Fusik
When does my solution 3979876 give wrong answer?
2010-02-19 23:35:31 Piotr K±kol
There are only letters: I,V,X,L,C,D,M. Then you print as many M's as you need.
So for example M*M is 1000*1000 so 1000 of M's and MMMM + MMMM is MMMMMMMM.
Good luck. ;-)

Last edit: 2010-02-19 23:37:10
2010-02-19 15:50:05 Alessandro (Xiforimpula)
How values greater than 3999 are represented in input?
SPOJ System © 2012 Sphere Research Labs | Projekty informatyczne i aplikacje na zamówienie. All Rights Reserved.