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)的更多相关文章

  1. UVA 465 (13.08.02)

     Overflow  Write a program that reads an expression consisting of twonon-negative integer and an ope ...

  2. UVA 10494 (13.08.02)

    点此连接到UVA10494 思路: 采取一种, 边取余边取整的方法, 让这题变的简单许多~ AC代码: #include<stdio.h> #include<string.h> ...

  3. UVA 424 (13.08.02)

     Integer Inquiry  One of the first users of BIT's new supercomputer was Chip Diller. Heextended his ...

  4. UVA 10194 (13.08.05)

    :W Problem A: Football (aka Soccer)  The Problem Football the most popular sport in the world (ameri ...

  5. UVA 253 (13.08.06)

     Cube painting  We have a machine for painting cubes. It is supplied withthree different colors: blu ...

  6. 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 ...

  7. UVA 10499 (13.08.06)

    Problem H The Land of Justice Input: standard input Output: standard output Time Limit: 4 seconds In ...

  8. UVA 10025 (13.08.06)

     The ? 1 ? 2 ? ... ? n = k problem  Theproblem Given the following formula, one can set operators '+ ...

  9. UVA 536 (13.08.17)

     Tree Recovery  Little Valentine liked playing with binary trees very much. Her favoritegame was con ...

随机推荐

  1. 数据库(学习整理)----3--Oracle创建表和设置约束

    BBS论坛表设计 包含的表:BBSusers(用户表),BBSsection(版块表),BBStopic(主贴表),BBSreply(跟帖表) 表结构 1)BBSusers 字段名 字段说明 数据类型 ...

  2. Apache提示You don't have permission to access / on this server问题解决

    测试时遇到将一本地目录设置为一apache的虚拟主机,在httpd-vhosts.conf文件中进行简单设置,然后在hosts文件中将访问地址指向本地,启动apache,进行访问,却出现了You do ...

  3. javascript 学习笔记之面向对象编程(一):类的实现

    ~~想是一回事,做是一回事,写出来又是一回事~~一直以来,从事C++更多的是VC++多一些,从面向过程到面向对象的转变,让我对OO的编程思想有些偏爱,将一个客观存在的规律抽象出来总是让人比较兴奋,通过 ...

  4. winform C#屏幕右下角弹出消息框并自动消失

    ①弹出信息框后慢慢下降消失 在主窗体中新增按钮重命名为btnShowAndDisappearMessages,在click事件中写如下代码: private void btnShowAndDisapp ...

  5. 利用青瓷布局自定义加载的场景,而不是自己改写qici-loading

    加载界面如果全部通过自己手动布局不仅不美观,还很难控制.借用原生的场景切换加载效果,来实现我们游戏的加载效果. 没有做加载修改的原来的加载顺序:   黑乎乎界面->(游戏定制的加载)你的第一个场 ...

  6. pushState与replaceState区别

    history.pushState(state, title, url) 将当前URL和history.state加入到history中,并用新的state和URL替换当前.不会造成页面刷新. sta ...

  7. oracle系列索引

    今天终于把oracle入门的知识通篇过了一遍. 一篇文章没有写,先做个索引.把知识系统的梳理下. 数据库基本概念-oracle介绍 oracle安装,配置,启动 oracle工具 sqlplus 用户 ...

  8. 从文章"避免复制与粘贴"到文章"Extract Method"的反思(3)

    在牛人的博客中提到了..如果你的代码可以copy-past的时候,那么久证明你的代码出现了重复.而这种重复仅仅是虚假的代码行的增加而不是像其他的代码复用那样降级成本. copy-pase代码意味着你违 ...

  9. finalspeed服务器端和客户端安装

    https://www.91yun.org/archives/2775 https://www.91yun.org/archives/615 1.首先安装服务器端:一键安装代码 wget -N --n ...

  10. jquery添加元素

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <head> ...