悠游


私信TA

用户名:uq_87643911115

访问量:3993

签 名:

你好

等  级
排  名 60
经  验 10464
参赛次数 0
文章发表 203
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

大家好!我是糕手

解题思路:

注意事项:

参考代码:

#include<stdio.h>
#include<string.h>
#define MAXSIZE 200
int main()
{
	char a[MAXSIZE],b[MAXSIZE];
	scanf("%s\n%s",a,b);
	int len_a=strlen(a);
	int len_b=strlen(b);
	int a1[MAXSIZE]={0},b1[MAXSIZE]={0};
	int count_a=0,count_b=0;
	for(int i=len_a-1;i>=0;i--)
	{
	    a1[count_a]=a[i]-'0';
	    count_a++;
	}
	for(int i=len_b-1;i>=0;i--)
	{
	    b1[count_b]=b[i]-'0';
	    count_b++;
	}
	int count=0;
	count=count_a>count_b?count_a:count_b;
	for(int i=0;i<count;i++)
	{
	    int t=a1[i]-b1[i];
	    a1[i]=t;
	    if(t<0)
	    {
	        a1[i]+=10;//借位
	        a1[i+1]-=1;//高位减一
	    }
	}
	int *p=a1+MAXSIZE-1;
	while(*p==0&&p>=a1)
	{
	    p--;
	}
	while(p>=a1)//倒序输出
	{
	    printf("%d",*p);
	    p--;
	}
	return 0;
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区