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 ...
随机推荐
- jquery”ScriptResourceMapping
要“jquery”ScriptResourceMapping.请添加一个名为 jquery (区分大小写)的 ScriptResourceMapping.”的解决办法. 1.先将aspnet.scri ...
- Sql Server内置函数实现MD5加密
实例 MD5加密“123456”: HashBytes('MD5','123456') 结果:0xE10ADC3949BA59ABBE56E057F20F883E (提示:看完最后,结果要进行转换.) ...
- ios专题 - sandbox机制
[原创]http://www.cnblogs.com/luoguoqiang1985 ios在安装APP时,把APP的偏好设置与数据放在sandbox里.sandbox通过一系列细颗粒度控制APP访问 ...
- C++语言体系设计哲学的一些随想(未完待续)
对于静态类型语言,其本质目标在于恰当地操作数据,得到期望的值.具体而言,需要: (1)定义数据类型 你定义的数据是什么,是整形还是浮点还是字符.该类型的数据可以包含的值的范围是什么. (2)定义操作的 ...
- 网站开发常用jQuery插件总结(九)侧边栏插件pageslide
一.pageslide插件功能 实现现实隐藏侧边栏的功能.插件可以读取另个一html,也可以是当前页面中的元素. 二.pageslide官方地址 http://srobbin.com/jquery-p ...
- input 表单点击消失离开出现
效果1: <input type="text" name="textfield" value="这里是提示内容" onclick=&q ...
- Object之魔术函数__toString() 直接输出对象引用时自动调用
__toString()是快速获取对象的字符串信息的便捷方式 在直接输出对象引用时自动调用的方法. __toString()的作用 当我们调试程序时,需要知道是否得出正确的数据.比如打印一个对象时,看 ...
- 运用预加载提升H5移动页面的用户体验
原文地址:http://www.grycheng.com/?p=2188 在做h5移动页面,相信大家一定碰到过页面已经打开,但是里面的图片还未加载出来的情况,这种问题虽然不影响页面的功能,但是不利于用 ...
- Cinder-2 窗口的创建过程
通过TinderBox生成的代码很简单,整个代码如下: #include "cinder/app/AppNative.h" #include "cinder/gl/gl. ...
- [BZOJ 1058] [ZJOI2007] 报表统计 【平衡树】
题目链接:BZOJ - 1058 题目分析 这道题看似是需要在序列中插入一些数字,但其实询问的内容只与相邻的元素有关. 那么我们只要对每个位置维护两个数 Ai, Bi, Ai 就是初始序列中 i 这个 ...