hrbust 1415 Elementary arithmetic【高精度模拟】水题
来源:互联网 发布:网络老冰棍是什么意思 编辑:程序博客网 时间:2024/05/17 01:18
Elementary arithmeticTime Limit: 1000 MSMemory Limit: 65536 KTotal Submit: 79(37 users)Total Accepted: 40(37 users)Rating: Special Judge: NoDescription
Many pupils in learning in the addition, found "binary" especially easy to make a mistake. Your task is to calculate in a + b process "binary" the number of times and output. (you input number no more than 9 digits).For example: when 7 add 6,you will binay 1 then ge 13.
InputThere are multiple test cases.
For each test case:
Line 1. This line contains two integers a, b (0 ≤ a, b ≤2000000000).
Process to the end of file.
OutputFor each test case:
Line 1. Output the sum of carry.
Sample Input5 6
55 555
1231 5941
Sample Output1
2
1
AuthorInuyasha@HRBUST题目大意:给你两个数a,b,让你求出a+b的时候进位的次数。
思路:
直接模拟大数加法即可。
注意清空数组
Ac代码:
#include<stdio.h>#include<string.h>#include<iostream>using namespace std;char a[15];char b[15];int aa[15];int bb[15];int cc[15];int main(){ while(~scanf("%s%s",a,b)) { memset(cc,0,sizeof(cc)); memset(bb,0,sizeof(bb)); memset(aa,0,sizeof(aa)); int cont=0; for(int i=strlen(a)-1;i>=0;i--) { aa[cont++]=a[i]-'0'; } cont=0; for(int i=strlen(b)-1;i>=0;i--) { bb[cont++]=b[i]-'0'; } for(int i=0;i<max(strlen(a),strlen(b));i++) { cc[i]=aa[i]+bb[i]; } int output=0; for(int i=0;i<max(strlen(a),strlen(b));i++) { if(cc[i]>=10) { cc[i]-=10; cc[i+1]++; output++; } } printf("%d\n",output); }}
0 0
- hrbust 1415 Elementary arithmetic【高精度模拟】水题
- HRBUST 1180 队列模拟
- HRBUST 1014 模拟
- HRBUST 1908 A+B+C 高精度加法
- POJ 2602 Superlong sums (高精度,模拟,水题)
- POJ 2562 Primary Arithmetic(高精度)
- hoj 1368 Very Simple Arithmetic java 高精度
- HRBUST 1652 模拟链表
- HRBUST 1547 模拟链表
- hrbust 2104 Encryption 【模拟+STL】
- hrbust 1594 Gragon Ball【模拟】
- hrbust 1039 修路【二分+模拟】
- hrbust 1739 Sort Problem 模拟
- hdu 5920(高精度 + 模拟)
- hrbust 哈理工oj 1330 邂逅【模拟】
- Hrbust 2313 Circle Fan【模拟+思维】
- 【总结】高精度计算(Arbitrary-precision arithmetic)的模板 CPP Language
- Simulate Anneal Arithmetic (SAA,模拟退火算法)
- php 导入excel解析提示 Fatal error: Class 'ZipArchive' not found解决方法
- mini2440之IIC通信协议
- 02表格布局
- 网络传输的加密与解密
- Codeforces #331 Div2 D
- hrbust 1415 Elementary arithmetic【高精度模拟】水题
- 重构以前的代码
- c++知识
- Kylin Cube Build流程
- Leetcode 367. Valid Perfect Square (Medium) (cpp)
- WCF配置
- poj 1019 Number Sequence
- hbase_1 [get_counter 报错]
- 02布局总结