9 degrees OJ 1003 A + B

Source: Internet
Author: User

Question Analysis:

Use the and B strings to store the two groups of input data. First, remove the non-numeric symbols and obtain the value of the number. Then determine the plus and minus signs. If there is a negative number, it is in the beginning of the string. After the judgment, the data value is obtained for calculation.

 


Source code:


[Cpp]
# Include <iostream>
# Include <string>
Using namespace std;
 
Int main ()
{
String A, B;
While (cin> A> B)
{
Long m = 0, n = 0;
For (int I = 0; I <A. length (); I ++)
{

If (A [I]> = '0' & A [I] <= '9 ')
{
// Obtain the value corresponding to the character
M = m * 10 + A [I]-'0 ';

}
}
For (int I = 0; I <B. length (); I ++)
{

If (B [I]> = '0' & B [I] <= '9 ')
{
// Obtain the value corresponding to the character
N = n * 10 + B [I]-'0 ';

}
}
 
If (A [0] = '-')
{
M = 0-m;
}
If (B [0] = '-')
{
N = 0-n;
}
 
Cout <m + n <endl;
 
}
Return 0;
 
}

# Include <iostream>
# Include <string>
Using namespace std;

Int main ()
{
String A, B;
While (cin> A> B)
{
Long m = 0, n = 0;
For (int I = 0; I <A. length (); I ++)
{

If (A [I]> = '0' & A [I] <= '9 ')
{
// Obtain the value corresponding to the character
M = m * 10 + A [I]-'0 ';

}
}
For (int I = 0; I <B. length (); I ++)
{

If (B [I]> = '0' & B [I] <= '9 ')
{
// Obtain the value corresponding to the character
N = n * 10 + B [I]-'0 ';

}
}

If (A [0] = '-')
{
M = 0-m;
}
If (B [0] = '-')
{
N = 0-n;
}

Cout <m + n <endl;

}
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.