POJ 2389
发布日期:2021-06-30 15:30:55
浏览次数:2
分类:技术文章
本文共 1613 字,大约阅读时间需要 5 分钟。
Bull Math
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 16175 | Accepted: 8268 |
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
111111111111111111111111
Sample Output
12345679011110987654321
Source
代码:
#include#include #include using namespace std;int sum[2001];int s1[50] , s2[50];string str1 , str2;void multiply(){ int i , j , k; int l1 , l2 , len; memset(sum,0,sizeof(sum)); memset(s1,0,sizeof(s1)); memset(s2,0,sizeof(s2)); l1 = str1.size(); l2 = str2.size(); for(i = l1-1 , k = 1;i >= 0;i-- , k++) s1[k] = str1[i]-48; for(i = l2-1 , k = 1;i >= 0;i-- , k++) s2[k] = str2[i]-48; for(i = 1;i <= l1;i++ ) { for(j = 1;j <= l2;j++) { sum[i+j-1] += s1[i]*s2[j]; sum[i+j] += sum[i+j-1]/10; sum[i+j-1] %= 10; } } len = 2000; while(len--) { if(sum[len] != 0) break; } for(;len >= 1;len--) cout< >str1>>str2) { multiply(); } return 0;}
转载地址:https://joycez.blog.csdn.net/article/details/82822226 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年04月18日 00时47分50秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
公钥和私钥生成规则
2019-05-01
私钥加密
2019-05-01
私钥加密私钥解密
2019-05-01
私钥加密公钥解密
2019-05-01
获取私钥key对象
2019-05-01
获取公钥对象
2019-05-01
什么是数字签名
2019-05-01
数字签名原理
2019-05-01
锁的释放流程-ReentrantLock.unlock
2019-05-01
锁的释放流程-ReentrantLock.tryRelease
2019-05-01
锁的释放流程-unparkSuccessor
2019-05-01
ConcurrentHashMap的源码分析-tryPresize
2019-05-01
生产者消费者的实际使用
2019-05-01
阻塞队列的使用案例-注册成功后增加积分
2019-05-01
序列化的高阶认识-Transient 关键字
2019-05-01
序列化的高阶认识-绕开 transient 机制的办法
2019-05-01
Java 序列化的一些简 单总结
2019-05-01
分布式架构下常见序列化技术-了解序列化的发展
2019-05-01
Java判断字符串是否为数字(浮点类型也包括)
2019-05-01
DNS服务各功能实现方法
2019-05-01