前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >1754: [Usaco2005 qua]Bull Math

1754: [Usaco2005 qua]Bull Math

作者头像
HansBug
发布2018-04-11 10:31:12
6090
发布2018-04-11 10:31:12
举报
文章被收录于专栏:HansBug's LabHansBug's Lab

1754: [Usaco2005 qua]Bull Math

Time Limit: 5 Sec  Memory Limit: 64 MB

Submit: 398  Solved: 242

[Submit][Status][Discuss]

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

题解:萌萌哒高精度乘法= =

代码语言:javascript
复制
 1 /**************************************************************
 2     Problem: 1754
 3     User: HansBug
 4     Language: Pascal
 5     Result: Accepted
 6     Time:0 ms
 7     Memory:376 kb
 8 ****************************************************************/
 9  
10 var
11    i,j,k,l,m,n:longint;
12    a,b,c:array[0..10000] of longint;
13    s1,s2:ansistring;
14 begin
15      readln(s1);
16      readln(s2);
17      a[0]:=length(s1);
18      for i:=1 to a[0] do a[i]:=ord(s1[a[0]+1-i])-48;
19      b[0]:=length(s2);
20      for i:=1 to b[0] do b[i]:=ord(s2[b[0]+1-i])-48;
21      c[0]:=a[0]+b[0];
22      for i:=1 to a[0] do
23          for j:=1 to b[0] do
24              begin
25                   c[i+j-1]:=c[i+j-1]+a[i]*b[j];
26                   c[i+j]:=c[i+j]+c[i+j-1] div 10;
27                   c[i+j-1]:=c[i+j-1] mod 10;
28              end;
29      while (c[0]>1) and (c[c[0]]=0) do dec(c[0]);
30      for i:=c[0] downto 1 do write(c[i]);
31      writeln;
32      readln;
33 end.     
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015-04-14 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1754: [Usaco2005 qua]Bull Math
  • Description
  • Input
  • Output
  • Sample Input
  • Sample Output
  • HINT
  • Source
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档