zoukankan      html  css  js  c++  java
  • UVA 10106 Product

    将数学运算过程程序化,注意地址的变动,缩位进位就可以啦!

    #include<stdio.h>
    #include<string.h>
    #define MAXN1 250 + 10
    #define MAXN2 500 + 10
    char s1[MAXN1], s2[MAXN1];
    int num[MAXN2],num1[MAXN1],num2[MAXN1];
    void solve()
    {
    int len1 = strlen(s1);
    for(int i = 0; i < len1; i ++)
    num1[i] = s1[len1-i-1] - '0';
    int len2 = strlen(s2) ;
    for(int j = 0; j < len2; j ++)
    num2[j] = s2[len2-1-j] - '0';
    for(int p = 0; p < len2; p ++)
    {
    for(int q = 0; q < len1; q ++)
    {
    num[p+q] += num2[p] * num1[q];//printf("num[p+q]=%d",num[p+q]);
    if(num[p+q]>9)
    {
    num[p+q+1] += num[p+q]/10;
    num[p+q] %= 10;
    }
    }
    }
    }
    void output()
    {
    int i;
    for(i = MAXN2; i >= 0; i --)
    {
    if(i == 0) break;
    if(num[i] != 0) break;
    }
    for(int j = i; j >=0; j --)
    printf("%d",num[j]);
    printf("\n");
    }
    void input()
    {
    while(scanf("%s",s1) == 1)
    {
    memset(num,0,sizeof(num));
    scanf("%s",s2);
    solve();
    output();
    }
    }
    int main()
    {
    input();
    return 0;
    }



  • 相关阅读:
    HDU
    Hdu 5072 Coprime(容斥+同色三角形)
    HDU
    HTML常用基础标签
    简单session实现
    前端中的 IoC 理念
    怎样做页面界限
    Reset 对象属性
    SQL注入
    js:表单校验(获取元素、事件)
  • 原文地址:https://www.cnblogs.com/yuzhaoxin/p/2294079.html
Copyright © 2011-2022 走看看