140730summer training .txt

Source: Internet
Author: User
1. addition and subtraction of large numbers
Train of Thought Analysis:
1. Use data as a string input (gets (s ))
2. Convert the memory type to an integer type and store it in reverse order.
Char? Int I = 0, j = len-1, int [I ++] = char [j --]
3. Starting from the first place,
If sum> 9, int [I] = sum % 10, int [I + 1] + = sum/10;
4. Input
1> judge whether int [Len] is 0. If yes, Skip. If not, output.
2> output int [(len-1) --];
Exercise questions hdoj1002
# Include <stdio. h>
# Include <string. h>
Int main ()
{
Int T;
Char A [1100], B [1100], Beitai [1100];
Int C [1100], d [1100], sum [1100];
Int I, j, BT, k = 1;
Int Lena, lenb;
Scanf ("% d", & T );
Getchar ();
While (t --)
{
Scanf ("% S % s", a, B );
Getchar ();
Lena = strlen ();
Lenb = strlen (B );
Memset (C, 0, sizeof (c ));
Memset (D, 0, sizeof (d ));
Memset (sum, 0, sizeof (SUM ));
For (I = 0, j = lena-1; I <Lena; I ++, j --)
C [J] = A [I]-'0 ';
For (I = 0, j = lenb-1; I <lenb; I ++, j --)
D [J] = B [I]-'0 ';
If (Lena <lenb)
{
Bt = Lena;
Lena = lenb;
Lenb = Bt;
}
For (I = 0; I <= Lena; I ++)
{
Sum [I] = C [I] + d [I] + sum [I];
If (sum [I]/10> 0)
{
Sum [I + 1] = sum [I]/10;
Sum [I] % = 10;
}
}
Printf ("case % d: \ n", k );
K ++;
Printf ("% S + % s =", a, B );
If (sum [Lena]! = 0)
Printf ("% d", sum [Lena]);
For (I = lena-1; I> = 0; I --)
Printf ("% d", sum [I]);
Printf ("\ n ");
If (T! = 0)
Printf ("\ n ");
}
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.