Submit | All submissions | Best solutions | Back to list |
ROMANCAL - Roman calculator |
Wersja polska | English version |
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: | 2.484s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS OBJC SCM qobi VB.NET |
Resource: | Roman numerals |
hide comments
2011-02-08 19:04:50 Piotr KÄ…kol
9000. |
|
2011-02-07 04:08:12 Hallvard Norheim Bø
What is the upper limit on the output string length? |
|
2010-09-01 09:18:44 Piotr Fusik
Thank you. |
|
2010-08-31 19:45:06 Piotr KÄ…kol
For example: MCDLXXIV % LVII
:-) |
|
2010-08-31 19:10:07 Piotr Fusik
Okay, that was Perl 5.12 vs 5.10 incompatibility. How about 3984519 ? |
|
2010-08-30 16: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 16:54:23 |
|
2010-08-30 14:44:18 Piotr Fusik
When does my solution 3979876 give wrong answer? |
|
2010-02-19 22: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 22:37:10 |
|
2010-02-19 14:50:05 Alessandro Ferreira - UFMS
How values greater than 3999 are represented in input? |