测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A23609. 完善程序 : 高精度减法输入两个高精度数a和b,输出a-b的值。程序中使用了运算符重载:运算符重载,就是对已有的运算符重新进行定义,赋予其另一种功能,以适应不同的数据类型的运算。#include<cstdio> #include<iostream> #include<string> using namespace std; const int N=10100; struct big{ int d…

单选题 较易

题目描述

完善程序 : 高精度减法

输入两个高精度数a和b,输出a-b的值。

程序中使用了运算符重载:运算符重载,就是对已有的运算符重新进行定义,赋予其另一种功能,以适应不同的数据类型的运算。

#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
const int N=10100;
struct big{
    int d[N];
    int len;
};
big a,b;
char s[N];
big read(){//读入大整数
    big c;
    memset(c.d,0,sizeof(c.d));
    scanf("%s",s+1);
    int n=strlen(s+1);
    for(int i=1;i<=n;i++)
    	c.d[i] = ①  ;
    	clen=n;
    	return c;
}

bool operator >=(big a,big b){//重载>= 
    int n=a.len,m=b.len;
    if(n>m)return 1;
    if(n<m)return 0;
    for(int i=n;i>0;i--){
        if(a.d[i]>b.d[i]) return 1;
        if(a.d[i]<b.d[i])return 0;
    }
    return 1;
}

big operator-(big a,big b){//重载
    int n=a.len;
    for(int i=1;i<=n;i++){
        if(  ② ){ 
        a.d[i+1]--;
        (  ③ );
        }
        a.d[i]=b.d[i];
    }
    while(  ④ )n--;
    a.len=n;
    return a;
}

void write(big a){//输出大整数
    for(int i=a.len;i>0;i--);printf("%d",a.d[i]);printf("\n");
}

int main(){
    a=read();
    b=read();
    if(a>=b){
        write(a-b);
    }else{
        printf("-");
        (  ⑤ );
    }
    return 0;
}

① 处应填(    )

选项(单选)

上一题 下一题