• A1087. 高精度加法


    体验一下,高精度的算法

    /*
    * =====================================================================================
    *
    * Filename: a1087.c
    *
    * Description: Rainboy_RT
    *
    * Version: 1.0
    * Created: 2014-07-04 14:54:08
    * Revision: none
    * Compiler: gcc
    *
    * Author: Rainboy (mn), 597872644@qq.com
    * Company: NONE
    *
    * =====================================================================================
    */

    #include <stdio.h>

    #define max 100
    char str1[max+1],str2[max+1];
    int n1[max+1],n2[max+1],n3[max+1];
    int lena,lenb,lenc;
    int i,j,k,l;
    int main(int argc, const char *argv[])
    {
    scanf("%s",str1);
    scanf("%s",str2);
    lena = strlen(str1); lenb = strlen(str2);
    for (i = 1; i <= lena; i++) {
    n1[lena-i+1] = str1[i-1] -48;//高位在后,低位在前
    }

    for (i = 1; i <= lenb; i++) {
    n2[lenb-i+1] = str2[i-1] -48;
    }
    i =1;j=0;
    while ((i <=lena) || (i <= lenb)) {
    n3[i] = n2[i]+n1[i] +j;
    j = n3[i] / 10;
    n3[i] = n3[i] % 10;
    i++;
    }
    if (j >0 ) {
    lenc = i;
    n3[i] = j;
    }
    else
    lenc = i-1;

    for (i = lenc; i >0; i--) {
    printf("%d",n3[i]);
    }

    return 0;
    }

  • 相关阅读:
    CMDB开发
    运维相关开源项目
    SendMessage,BroadcastMessage
    C# System.IO.Path
    Unity[C#] Reflection Use
    Unity By Reflection Update Scripts
    Dictionary CovertTo List
    Unity 脚本的未来发展
    使用Doxygen生成C#帮助文档
    Spine Skeleton Animation(2D骨骼动画)
  • 原文地址:https://www.cnblogs.com/rainboy/p/3824460.html
Copyright © 2020-2023  润新知