2016/7/6 High Precision calculator-minus (Shen Gao precision)

Source: Internet
Author: User

Cough, I unkind, so, I wrote again ...

Source:

#include <stdio.h>
#include <string.h>
Char s1[1000];
int a[1000]={0},b[1000]={0},c[1000]={0};
int main ()
{
int i,j,z,l1,l2,l,o;
Freopen ("Hp-.in", "R", stdin);
Freopen ("Hp-.out", "w", stdout);
scanf ("%s", S1);
L1=strlen (S1);
for (i=0;i<=l1-1;i++)//convert S1 (meiosis) to a number and store in reverse a array
a[l1-1-i]=s1[i]-' 0 ';
scanf ("%s", S1);
L2=strlen (S1);
for (i=0;i<=l2-1;i++)//convert S1 (meiosis) to a number and deposit in reverse to B array
b[l2-1-i]=s1[i]-' 0 ';

if (L1==L2) {
for (j=l1;j>=0;j--)
{
if (A[j]>b[j])//a Large
{
o=0;
Break
}
if (B[j]>a[j])//b Large
{
O=1;
Break
}
}
}
if (l1>l2| | o==0)//a Big time
{
L=L1;
for (i=0;i<l;i++)
{
if (A[i]<b[i])
{
a[i]=a[i]+10;
A[i+1]-=1;
}
C[i]=a[i]-b[i];
}
while (l>1&&c[l-1]==0) l--; To give up the useless 0 in the high
for (i=l-1;i>=0;i--)//output
{
printf ("%d", c[i]);
}
}
Else
{
printf ("-");
L=L2;
for (i=0;i<l;i++)
{
if (A[i]>b[i])
{
b[i]=b[i]+10;
B[i+1]-=1;
}
C[i]=b[i]-a[i];
}
while (l>1&&c[l-1]==0) l--; To give up the useless 0 in the high
for (i=l-1;i>=0;i--)//output
{
printf ("%d", c[i]);
}
}

return 0;
}

from the group:

Chengdu Seven high-Tech campus OI2015 information Competition Ice Cane

http://www.cnblogs.com/chentao1c/--Ice Cane

2016/7/6 High Precision calculator-minus (Shen Gao precision)

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.