Sicily 1381 (High Precision)

Source: Internet
Author: User

# Include "iostream" # include "string" # include "string. H "# include" sstream "using namespace STD; int main () {int t; string str1, str2; // The input two integers are represented by strings CIN> T; while (t --) {CIN> str1> str2; int length1 = str1.size (); int lengh2 = str2.size (); int * A = new int [length1]; int * B = new int [lengh2]; for (INT I = 0; I <length1; I ++) // converts a string to a number, save in the array {stringstream S1; S1 <str1 [I]; S1> A [I];} For (INT I = 0; I <leng2; I ++) {stringstream S2; S2 <str2 [I]; S2> B [I];} int * c = new int [length1 + leng22. // The C array stores the result memset (C, 0, 4*(length1 + leng22.) after the two integers are multiplied )); int S = 0; For (INT I = length2-1; I> = 0; I --, s ++) {int K = s; For (Int J = length1-1; j> = 0; j --) // obtain the result based on the multiplication law {C [k] + = A [J] * B [I]; k = k + 1 ;}}for (INT I = 0; I <(length1 + length1); I ++) // determines whether carry is required! If (C [I]> = 10) {C [I + 1] + = C [I]/10; C [I] = C [I] % 10 ;} int Q; For (q = (length1 + length1)-1; q> = 0; q --) // you can check whether there is 0 in front of the array. If so, remove it! {If (C [Q]! = 0) {for (INT I = Q; I> = 0; I --) cout <C [I]; break;} If (q = 0) // if all the values in the array are 0, output 0! Cout <0 ;}cout <Endl ;}}

Related Article

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.