1004 large numbers

Source: Internet
Author: User

The addition of large numbers is a copy template. Note that if M is smaller than 3, it will definitely not work, because the smallest is a triangle. The value range of M is 3 <= m <= n + p.

# Include <iostream> # include <string> using namespace STD; string n, m, p; string sum (string S1, string S2) {If (s1.length () <s2.length () {string temp = S1; S1 = S2; S2 = temp;} For (INT n1 = s1.length ()-1, n2 = s2.length ()-1; n1> = 0; N1 --, N2 --) {S1 [N1] = char (S1 [N1] + (N2> = 0? S2 [n2]-'0': 0); If (S1 [N1]-'0'> = 10) {S1 [N1] = char (S1 [N1]-'0') % 10 + '0'); If (N1) S1 [n1-1] ++; else S1 = '1' + S1 ;}} return S1 ;}int main () {While (CIN >>n> M >> p) {int len_n = n. length (); int len_m = m. length (); If (len_m = 1 & M <"3") printf ("NO \ n "); else if (len_m <len_n | len_m = len_n & M <n) printf ("Yes \ n"); else {string temp = sum (n, p ); int len_t = temp. length (); If (len_t> len_m | (len_t = len_m & (temp> M | temp = m) printf ("Yes \ n "); else printf ("NO \ n") ;}// system ("pause"); Return 0 ;}

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.