A-B problem(高精度减法)

本博客探讨了A-B Problem,即处理大数减法的问题。由于数据规模超出long long int范围,因此需要使用数组来模拟减法运算,并在每次运算后重新初始化数组以确保正确性。给出了样例输入和输出,展示如何处理非负整数的减法操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A-B problem

题目传送门
Description
Now, Give you two intgers A and B , Please calculate the value of A minus B.
Attation: A、Band A-B are all non-negative numbers.

Input
Each line will contain two integers AA and BB.Process to end of file.(EOFEOF)

Output
For each case, Please output the value of A minus B

Sample Input 1
5 3
4 1

Sample Output 1
2
3
由于这个题的数据比较大,无法用long long int 表示,所以要用数组模拟这一减法问题。要注意进行完一次运算后对数组进行初始化。

#include<stdio.h>
int main()
{
    char x[1000],y[1000];
    int l[1000],m[1000],len1,len2;
    while(scanf("%s%s",&x,&y)!=EOF)
    {
        for(int i=0;i<1000;i++)
            {l[i]=0;m[i]=0;}
        len1=strlen(x);len2=strlen(y);
        for(int i=0,j=len1-1;j>=0;j--,i++)
            l[i]=x[j]-'0';
        for(int i=0,j=len2-1;j>=0;j--,i++)
            m[i]=y[j]-'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值