Test instructions: Give two large integers to determine which one is larger. Large integers are given in "AB" form, "a" is an integer without a leading 0 (greater than 0, not more than 1e9), and "B" is a number (possibly empty) factorial symbol ("!"). For example: 3!! =6!=720
Solution: Set two large integer form a part of the A,b;b section respectively has n1,n2 a symbol. Assuming N1 > n2, then we just need to determine the size of AA and B, where A is (N1-N2) a factorial symbol. N1 = N2 or N1 < N2 time is similar. But be aware that there is a pit, when a is 0 or B is 0 o'clock, if a or B can be converted to 1, it is converted. Otherwise there might be pits, like 1!!!!! = 0!!
My Code
#include <algorithm>#include <iostream>#include <sstream>#include <cstdlib>#include <cstring>#include <cstdio>#include <string>#include <vector>#include <cmath>#include <set>#include <map>using namespace STD;typedef Long Longllclassextraordinarilylarge{ Public:stringComparestringXstringY) {stringANS1 ="X<y", Ans2 ="X=y", ANS3 ="X>y";intN1 =0; while(X.back () = ='! ') n1++, X.pop_back ();intN2 =0; while(Y.back () = ='! ') n2++, Y.pop_back (); ll a = STOL (x), B = Stol (y);if(A = =0&& N1 >0) A =1, n1--;if(b = =0&& n2 >0) B =1, n2--;if(N1 = = n2) {if(A < b)returnans1;Else if(A = = b)returnAns2;Else returnANS3; }Else if(N1 > N2) {ll c =1; for(inti =0; i < n1-n2; i++) {c =1; for(intj =1; J <= A; J + +) {c = c * J;if(C > B)returnANS3; } a = C; }if(A < b)returnans1;Else if(A = = b)returnAns2;Else returnANS3; }Else//n1 < N2{ll c =1; for(inti =0; i < n2-n1; i++) {c =1; for(intj =1; J <= B; J + +) {c = c * J;if(C > a)returnans1; } B = C; }if(A < b)returnans1;Else if(A = = b)returnAns2;Else returnANS3; } }};
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Topcoder SRM DIV1 250