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. C#动态二维数组输出

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Cons ...

  2. CSS+Javascript的那些框架

    CSS CSS 制作框架 SASS http://www.oschina.net/p/sass Blueprint  http://www.oschina.net/p/blueprintcss Ela ...

  3. JavaScript学习总结【2】、JS基础

    1.JS 命名规范 命名规范是很有必要的,可增强代码的可读性,一眼就能看懂要表达的意思,规范就是符合规则,使代码有利于后期维护,也能很大程度的提高开发效率.一个正常的网站有很多 JS 代码,如果在编写 ...

  4. CI源码引用使用--php引用demo,静态变量和引用关系

    CI源码引用使用在Common.php中,加载配置和类的方法 function &test() {     static $a = '';     if (!$a) {         $a ...

  5. 配置SHH集群

    ==特别要注意当前用户的问题== 1. 修改路由信息 vi /etc/hosts 10.211.55.15 hmaster1 10.211.55.16 hmaster2 10.211.55.17 hs ...

  6. decimall类型数据

    同样是decimal(18,5)   和 decimal(18,4)  在VB中经过几次转化过后,数据就有可能改变. 遇到的情况 decimal(18,5)到  decimal(18,4)转换过程中数 ...

  7. NET Core站点部署到Linux服务器

    .NET跨平台之旅:将QPS 100左右的ASP.NET Core站点部署到Linux服务器上 今天下午我们将生产环境中一个单台服务器 QPS(每秒请求数)在100左右的 ASP.NET Core 站 ...

  8. Java-反射再学习

    反射之中包含了一个“反”的概念,所以要想解释反射就必须先从“正”开始解释,一般而言,当用户使用一个类的时候,应该先知道这个类,而后通过这个类产生实例化对象,但是“反”指的是通过对象找到类. packa ...

  9. HTML Imports

    为什么需要导入? 先想想你在 web 上是如何加载不同类型的资源.对于 JS,我们有 <script src>.<link rel="stylesheet"> ...

  10. Netty高性能之道

    1. 背景 1.1. 惊人的性能数据 最近一个圈内朋友告诉我,通过使用Netty4 + Thrift压缩二进制编解码技术,他们实现了10W TPS(1K的复杂POJO对象)的跨节点远程服务调用.相比于 ...