zoukankan      html  css  js  c++  java
  • BZOJ 1754: [Usaco2005 qua]Bull Math

    Description

    Bulls are so much better at math than the cows. They can multiply huge integers together and get perfectly precise answers ... or so they say. Farmer John wonders if their answers are correct. Help him check the bulls' answers. Read in two positive integers (no more than 40 digits each) and compute their product. Output it as a normal number (with no extra leading zeros). FJ asks that you do this yourself; don't use a special library function for the multiplication. 输入两个数,输出其乘积

    Input

    * Lines 1..2: Each line contains a single decimal number.

    Output

    * Line 1: The exact product of the two input lines

    题解:

    高精度乘法即可。

    代码:

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    //by zrt
    //problem:
    using namespace std;
    char a[105],b[105];
    int c[105];
    int la,lb;
    int cc;
    int stk[105],top;
    int main(){
        #ifdef LOCAL
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
        #endif
        scanf("%s%s",a,b);
        la=strlen(a);
        lb=strlen(b);
        for(int i=0;i<la;i++) a[i]-='0';
        for(int i=0;i<lb;i++) b[i]-='0';
        for(int i=0;i<la/2;i++) swap(a[i],a[la-i-1]);
        for(int i=0;i<lb/2;i++) swap(b[i],b[lb-i-1]);
        for(int i=0;i<la;i++){
            for(int j=0;j<lb;j++){
                c[i+j]+=a[i]*b[j];
            }
        }
        for(int i=0;i<=100;i++){
            stk[top++]=(c[i]+cc)%10;
            cc=(c[i]+cc)/10;
        }
        while(stk[top-1]==0) top--;
        while(top){
            printf("%d",stk[--top]);
        }
        puts("");
        return 0;
    }
  • 相关阅读:
    Ado.Net 实体框架学习笔记3
    Ado.Net 实体框架学习笔记1
    PV3D的小练习~太阳系八大行星
    AS3数组的应用,flash制作流星雨~
    电脑安全措施小贴士(摘)
    Windows下MySql批处理命令
    命令行批量改文件名
    汉字转拼音(asp)(摘录)
    sql server login与user的区别(摘)
    MySql四舍五入
  • 原文地址:https://www.cnblogs.com/zrts/p/bzoj1754.html
Copyright © 2011-2022 走看看