Bzoj1754: [usaco 2005 Qua] Bull math

Source: Internet
Author: User
1754: [usaco 2005 Qua] Bull mathtime limit: 5 sec memory limit: 64 MB
Submit: 374 solved: 227
[Submit] [Status] Descriptionbulls are so much better at math than the cows. they can multiplyhuge integers together and get perfectly precise answers... or sothey say. farmer John wonders if their answers are correct. helphim check the Bulls 'answers. read in two positive integers (nomore than 40 digits each) and compute their product. output it asa normal number (with no extra leading zeros ). FJ asks that you do this yourself; don't use a special libraryfunction for the multiplication. input two numbers and output their product input * lines 1 .. 2: Each line contains a single decimal number. output * Line 1: The exact product of the two input linessample input11111111111111
1111111111

Sample output12345679011110987654321hintsource

Gold

Question:

Ha ha, the Gold Group has such a problem, explosion proof zero it...

Code:

 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 100000000024 25 #define maxn 1000026 27 #define maxm 500+10028 29 #define eps 1e-1030 31 #define ll long long32 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 100000000744 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("\n");85 86     return 0;87 88 }
View code

 

Bzoj1754: [usaco 2005 Qua] Bull math

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.