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.

Input

There are multiple test cases.

For each test case:

Line 1. This line contains two integers ab (0 ≤ a, b ≤2000000000).

Process to the end of file.

Output

For each test case:

Line 1. Output the sum of carry.

Sample Input

5 6

55 555

1231 5941

Sample Output

1

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
原创粉丝点击