UVA 10106 (13.08.02)
Product |
The Problem
The problem is to multiply two integers X, Y. (0<=X,Y<10250)
The Input
The input will consist of a set of pairs of lines. Each line in pair contains one multiplyer.
The Output
For each input pair of lines the output line should consist one integer the product.
Sample Input
12
12
2
222222222222222222222222
Sample Output
144
444444444444444444444444 题意: 大数相乘
做法, 看AC代码, 有注释, 自行理解, 不难~ AC代码:
#include<stdio.h>
#include<string.h> int main() {
char mul1[300], mul2[300];
char ch;
int ans[600];
int len1, len2;
int num1, num2;
int k, Sum;
while(gets(mul1) != NULL && gets(mul2) != NULL) {
memset(ans, 0, sizeof(ans));
len1 = strlen(mul1);
len2 = strlen(mul2);
//倒序第一个乘数:
for(int i = 0; i < len1/2; i++) {
ch = mul1[i];
mul1[i] = mul1[len1 - 1 - i];
mul1[len1 - 1 - i] = ch;
}
//倒序第二个乘数:
for(int i = 0; i < len2/2; i++) {
ch = mul2[i];
mul2[i] = mul2[len2 - 1 - i];
mul2[len2 - 1 - i] = ch;
}
//开始处理
for(int i = 0; i < len1; i++) {
num1 = mul1[i] - '0';
k = i;
for(int j = 0; j < len2; j++) {
num2 = mul2[j] - '0';
Sum = num1 * num2;
ans[k] = Sum % 10 + ans[k];
ans[k+1] = Sum / 10 + ans[k+1];
if(ans[k] > 9) {
ans[k+1] = ans[k] / 10 + ans[k+1];
ans[k] = ans[k] % 10;
}
k++;
}
}
//从后面开始查找第一个非零数, 然后倒序输出~
int pos;
for(int i = 599; i >= 0; i--) {
if(ans[i] != 0) {
pos = i;
for(int i = pos; i >= 0; i--)
printf("%d", ans[i]);
printf("\n");
break;
}
else if(i == 0 && ans[i] == 0)
printf("0\n");
}
}
return 0;
}
UVA 10106 (13.08.02)的更多相关文章
- UVA 465 (13.08.02)
Overflow Write a program that reads an expression consisting of twonon-negative integer and an ope ...
- UVA 10494 (13.08.02)
点此连接到UVA10494 思路: 采取一种, 边取余边取整的方法, 让这题变的简单许多~ AC代码: #include<stdio.h> #include<string.h> ...
- UVA 424 (13.08.02)
Integer Inquiry One of the first users of BIT's new supercomputer was Chip Diller. Heextended his ...
- UVA 10194 (13.08.05)
:W Problem A: Football (aka Soccer) The Problem Football the most popular sport in the world (ameri ...
- UVA 253 (13.08.06)
Cube painting We have a machine for painting cubes. It is supplied withthree different colors: blu ...
- UVA 573 (13.08.06)
The Snail A snail is at the bottom of a 6-foot well and wants to climb to the top.The snail can cl ...
- UVA 10499 (13.08.06)
Problem H The Land of Justice Input: standard input Output: standard output Time Limit: 4 seconds In ...
- UVA 10025 (13.08.06)
The ? 1 ? 2 ? ... ? n = k problem Theproblem Given the following formula, one can set operators '+ ...
- UVA 536 (13.08.17)
Tree Recovery Little Valentine liked playing with binary trees very much. Her favoritegame was con ...
随机推荐
- Javascript实现图片库效果
思路: 无序列表加载图片文件.用img标签加载一张图片作为占位符.当点击照片链接时,改变<a>元素的href属性.并且阻止浏览器的默认行为. 动态改变描述文字,在图片下方增加P标签.通过获 ...
- JavaWeb学习----JSP简介及入门(JSP结构及JSP处理)
[声明] 欢迎转载,但请保留文章原始出处→_→ 艾水及水:http://www.cnblogs.com/liuhepeng 文章来源:http://www.cnblogs.com/liuhepeng ...
- java_泛型(2016-11-17)
没有自己敲,这篇博客讲的不错,直接记录. 犯懒啊 重点关注 T,?以及擦除 Java总结篇系列:Java泛型:http://www.cnblogs.com/lwbqqyumidi/p/3837629. ...
- POJ 1159 Palindrome(LCS)
题目链接:http://poj.org/problem?id=1159 题目大意:给定一串字符,添加最少的字符,使之成为回文串. Sample Input 5 Ab3bd Sample Output ...
- 242. Valid Anagram(C++)
242. Valid Anagram Given two strings s and t, write a function to determine if t is an anagram of s. ...
- CentOS6.5 编译安装lnmp环境
参考:http://54im.com/tag/libmcrypt http://www.educity.cn/linux/1240338.html 设置防火墙,并开启3306 80端口:vi /etc ...
- ERP系统开发平台 (C#语言,支持多数据库)
C/S系统开发框架-企业版 V4.0 (Enterprise Edition) 简介: http://www.csframework.com/cs-framework-4.0.htm 适用软件:适合开 ...
- WPF Navigation导航
WPF导航这个话题,网上的解决方法有很多种,有点吃猪脚的感觉,弃之可惜,食之乏味. 不过还是简单聊聊吧. 常见的导航: 利用HyperLink导航,可以到某一个Page页面,也可以是外部链接,当然也可 ...
- 2016022609 - redis哈希命令集合
参考:http://www.yiibai.com/redis/redis_hashes.html Redis的哈希值是字符串字段和字符串值之间的映射,所以他们是表示对象的完美数据类型 在Redis中的 ...
- 《Journey》风之旅人;
俩个人在茫茫世界相遇,互不相识,却能互相取暖,一路旅程,看尽了美丽的风景,也共同经历了暴风雪,然而该来的人会来,该走的人会走,这不就是人生旅途?