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

    1754: [Usaco2005 qua]Bull Math

    Time Limit: 5 Sec  Memory Limit: 64 MB
    Submit: 374  Solved: 227
    [Submit][Status]

    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

    Sample Input

    11111111111111
    1111111111

    Sample Output

    12345679011110987654321

    HINT

    Source

    Gold

    题解:

    呵呵,金组出这种题,防爆零呢吧。。。

    代码:

     1 #include<cstdio>
     2 
     3 #include<cstdlib>
     4 
     5 #include<cmath>
     6 
     7 #include<cstring>
     8 
     9 #include<algorithm>
    10 
    11 #include<iostream>
    12 
    13 #include<vector>
    14 
    15 #include<map>
    16 
    17 #include<set>
    18 
    19 #include<queue>
    20 
    21 #include<string>
    22 
    23 #define inf 1000000000
    24 
    25 #define maxn 10000
    26 
    27 #define maxm 500+100
    28 
    29 #define eps 1e-10
    30 
    31 #define ll long long
    32 
    33 #define pa pair<int,int>
    34 
    35 #define for0(i,n) for(int i=0;i<=(n);i++)
    36 
    37 #define for1(i,n) for(int i=1;i<=(n);i++)
    38 
    39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
    40 
    41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
    42 
    43 #define mod 1000000007
    44 
    45 using namespace std;
    46 
    47 inline int read()
    48 
    49 {
    50 
    51     int x=0,f=1;char ch=getchar();
    52 
    53     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    54 
    55     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
    56 
    57     return x*f;
    58 
    59 }
    60 int n,m,a[maxn],b[maxn],c[maxn];
    61 char ch;
    62 
    63 int main()
    64 
    65 {
    66 
    67     freopen("input.txt","r",stdin);
    68 
    69     freopen("output.txt","w",stdout);
    70 
    71     ch=getchar();
    72     while(ch<='9'&&ch>='0')a[++n]=ch-'0',ch=getchar();
    73     for1(i,n>>1)swap(a[i],a[n+1-i]);
    74     ch=getchar();
    75     while(ch<='9'&&ch>='0')b[++m]=ch-'0',ch=getchar();
    76     for1(i,m>>1)swap(b[i],b[m+1-i]);
    77     for1(i,n)
    78      for1(j,m)
    79       c[i+j-1]+=a[i]*b[j];
    80     for1(i,n+m)c[i+1]+=c[i]/10,c[i]%=10;
    81     int t=n+m;
    82     while(!c[t])t--;
    83     for3(i,t,1)printf("%d",c[i]);
    84     printf("
    ");
    85 
    86     return 0;
    87 
    88 }
    View Code
  • 相关阅读:
    yum源
    存储计量单位排序
    博客园代码高亮
    磁盘配置
    软件包安装
    网络配置
    用户、组及权限控制
    Android开发项目中常用到的开源库
    使用百度地图时,Application类的onCreate执行两次的解决方案
    计算从1到n中,出现某位数字的次数
  • 原文地址:https://www.cnblogs.com/zyfzyf/p/4031781.html
Copyright © 2011-2022 走看看