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 ...
随机推荐
- 1 Yoga3 系统装机总结.
1- Yoga 3 存在串口驱动不安装, 那么触摸屏不能用的情况, 打破了以往对触摸屏-"纯外设" 的设想, 与系统有关!!! 2- 系统安装总结: 1) BIOS中设置UEFI ...
- WPF中TreeView数据结构解析
XAML.CS代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; usi ...
- PHP 编译问题PEAR package PHP_Archive not installed的解决
php 的编译时需要依赖pear package ,目前的问题错误"PEAR package PHP_Archive not installed",已经明显报出这个问题. 因此编译 ...
- canvas 之 - 精灵 钟表动画
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- ASP.NET MVC 中使用JavaScriptResult
在浏览器地址栏输入地址,在页面上想通过脚本弹出一个框,看到Controller下有个JavaScript方法,返回的类型是JavaScriptResult,于是想用这个方法弹出框, public Ac ...
- EFBaseDal
public class BaseDal<T> where T : class, new() { DataModelContainer db = new DataMod ...
- GHOST还原
整理日: 2015年2月16日 GHOST GHO2Disk STEP01 STEP02 STEP03 STEP04 STEP05 STEP06 STEP07
- require 书写约定
使用 Sea.js 书写模块代码时,需要遵循一些简单规则. 只是书写和调试时的规范!!!构建后的代码完全不需要遵循下面的约定!!!!!! 1. 正确拼写 模块 factory 构造方法的第一个参数 必 ...
- bzoj 1034: [ZJOI2008]泡泡堂BNB 貪心
1034: [ZJOI2008]泡泡堂BNB Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1398 Solved: 727[Submit][Sta ...
- Gradle在大型Java项目上的应用
在Java构建工具的世界里,先有了Ant,然后有了Maven.Maven的CoC[1].依赖管理以及项目构建规则重用性等特点,让Maven几乎成为Java构建工具的事实标准.然而,冗余的依赖管理配置. ...