Topcoder SRM DIV1 250

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.