蓝桥杯基础练习 高精度加法
来源:互联网 发布:java excel 日期格式 编辑:程序博客网 时间:2024/05/17 05:58
#include <cmath>#include <cstdio>#include <algorithm>#include <iostream>#include <cstring>using namespace std;//全局变量在没有赋值以前系统默认为0,而局部变量在没有赋值以前的值是不确定的,//所以在声明局部变量的时候一定要初始化。//用char 数组保存字符串时,结尾总是添加'\0'(ASCII为十进制0) char a[105],b[105];int c[105];void Swap(char *p,int n)//交换如输入1234,变成4321,这样个位在a[0],十位在a[1] {int i=0;while(i<=(n-1)/2){swap(p[i],p[n-1-i]);i++;}}int Cnt(char *p)//计算字符串个数 {int tmp=0,i=0;while(p[i++])tmp++;return tmp;}int main(){scanf("%s",a);scanf("%s",b);int c1=Cnt(a);int c2=Cnt(b);Swap(a,c1);Swap(b,c2);if(c1>c2)//如1234\0 {// 2300\0 (4321+32)while(c2<=c1){if(c2==c1){b[c2]='\0';c2++;}else{b[c2]='0';c2++;}}} else if(c2>c1) //如 2300\0 {// 1234\0 (32+4321) while(c1<=c2){if(c1==c2){a[c1]='\0';c1++;}else{a[c1]='0';c1++;}}}int i=0;while(a[i]||b[i]){int tmp=c[i]+(a[i]-'0')+(b[i]-'0');c[i]=tmp%10;c[i+1]+=tmp/10;i++;}if(c[i])//最后的一位进位处理 {for(int k=i;k>=0;k--)cout<<c[k];cout<<endl;}else{for(int k=i-1;k>=0;k--)cout<<c[k];cout<<endl;}return 0;}
0 0
- 蓝桥杯 基础练习 高精度加法
- 蓝桥杯基础练习 高精度加法
- 蓝桥杯基础练习 高精度加法
- 基础练习 高精度加法
- 基础练习 高精度加法
- 基础练习 高精度加法
- 基础练习 高精度加法
- 基础练习 高精度加法
- 基础练习 高精度加法
- 基础练习 高精度加法
- 基础练习 高精度加法
- 基础练习 高精度加法
- 基础练习 高精度加法
- 基础练习 高精度加法
- 蓝桥杯 VIP 基础练习 高精度加法
- 蓝桥杯:基础练习 阶乘计算 高精度加法
- 蓝桥杯 BASIC-29 基础练习 高精度加法
- (蓝桥杯)基础练习 高精度加法
- 修改Linux系统时间
- 网管的自我修养-信息系统
- CentOS 6、7下pptp vpn一键安装脚本
- ERROR ITMS-90168 MAC OSX 沙盒机制
- http和https80端口是为HTTP(HyperText Transport Protocol)即超文本传输协议开放的,此为上网冲浪使用次数最多的协议,主要用于WWW(World Wide Web
- 蓝桥杯基础练习 高精度加法
- mysql查询重复数据并保留一条
- G++和C++的区别(oj中)
- JDBC的工具类(简单实用,体现java封装特性)
- 安卓selinux权限修改(基于tiny4412开发板)
- lede 修改默认开启wifi 修改wan和lan口位置
- Unity 语音识别 详情版 和 发布过程中遇到的问题
- Spark 源代码 SparkContext
- linux虚拟机网络管理