Connection Status:
Competition Arena > ExtraordinarilyLarge
SRM 320 · 2006-09-30 · by brett1479 · Simple Math
Class Name: ExtraordinarilyLarge
Return Type: String
Method Name: compare
Arg Types: (string, string)
Problem Statement

Problem Statement

You need to handle two extraordinarily large integers. The good news is that you don't need to perform any arithmetic operation on them. You just need to compare them and see whether they are equal or one is greater than the other.

Given two Strings x and y, return either "x<y", "x>y" or "x=y" depending on the values represented by x and y. x and y each consist of a decimal integer followed zero or more '!' characters. Each '!' represents the factorial operation. For example, "3!!" represents 3!! = 6! = 720.

Notes

  • In case you don't know about factorials, here is a quick definition: 0! is defined as 1. For any positive integer n, n! is defined as n * [(n-1)!]. For example, 5! = 5 * 4 * 3 * 2 * 1 * 0! = 120.

Constraints

  • x and y will each contain between 1 and 50 characters, inclusive.
  • x and y will each consist of a non-negative integer less than 109, with no extra leading zeros, followed by zero or more '!' characters.
Examples
0)
"0!"
"1"
Returns: "x=y"
1)
"9!"
"999999999"
Returns: "x
2)
"9!!"
"999999999"
Returns: "x>y"
3)
"456!!!"
"123!!!!!!"
Returns: "x
4)
"5!"
"120"
Returns: "x=y"

Submissions are judged against all 164 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class ExtraordinarilyLarge with a public method string compare(string x, string y) · 164 test cases · 2 s / 256 MB per case

Submitting as anonymous