acgo题库
  • 首页
  • 题库
  • 学习
  • 天梯
  • 备赛

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
  • 资讯
  • 竞赛
  • 讨论
  • 团队
  • 商城
登录
注册
题目详情提交记录(0)
  • 大整数加法 题解

    userId_undefined
    skirmish
    题解仙人时空双修者秩序白银快乐小狗CSP-J一等奖BUG超度大师
    34阅读
    0回复
    3点赞
  • 题解(加注)

    #include<bits/stdc++.h> using namespace std; const int maxn=114514; char sb1[maxn], sb2[maxn]; int a[maxn], b[maxn], c[maxn]; //3,4,5:伟大无需多言 int main(){ ios_base::sync_with_stdio(false); //《万金油》 scanf("%s", sb1); scanf("%s", sb2); memset(c, 0, sizeof(c)); //初始化一下(后边要考) int lsx1 = strlen(sb1); int lsx2 = strlen(sb2); for(int i = 0; i < lsx1; i++) a[lsx1 - i - 1] = sb1[i] - '0';//遍历一下+此乃失传0年的倒序存储 for(int i = 0; i < lsx2; i++) b[lsx2 - i - 1] = sb2[i] - '0';//【同上】(其实就懒得写) int lsx3 = lsx1 > lsx2 ? lsx1 : lsx2; //《胡乱》赋值与《猎奇》表达式 for(int i=0; i < lsx3; i++){ c[i] += a[i] + b[i]; //《苹果派考糊了爷爷奶奶》 (作用:相加复制) if(c[i] >= 10){ //判断进位 c[i+1] = c[i]/10; //进位 c[i] = c[i]%10; //取余位 } } if(c[lsx3] > 0) lsx3++; //判断上面进位 int cnt = lsx3- 1; //查看前导零0 while(c[cnt] == 0) cnt--; //扔掉那该死的前导0 for(int i = cnt; i >= 0; i--) printf("%d", c[i]); return 0; }//Do not ask me anything.If you know,you know.(懂得都懂)

    userId_undefined
    改行当K佬
    时间刺客字符串·魔法使贪心·贪心尝试者ASCII炼金师数组·数组操作员维度操控者
    4阅读
    2回复
    1点赞
暂无数据

提交答案之后,这里将显示提交结果~

首页