UVa 10106 乘积
来源:互联网 发布:淘宝如何营销 编辑:程序博客网 时间:2024/05/21 17:36
/*
* 解题思路:
* 题意不难理解、主要是控制好就行、下面几种注意点
*1、例如99*99这种,最后还有高位进位
* 2、例如00000001*1,只输出一个1,前面0不输出
* 3、例如0000*101,只输出一个0
* 4、数组大小控制好,否则出现RE错
*/
#include <stdio.h>#include <string.h>#define A 500int main( ){ int x,y; int i,j; int in,tmp,flag; int len1,len2,len; char s1[ A ] , s2[ A ],ss[ A ],s[ A ]; while( ~scanf("%s%s",s1,s2) ) { len1 = strlen( s1 ); len2 = strlen( s2 ); if( len1 > len2 ) { strcpy( s , s1 ); strcpy( s1,s2 ); strcpy( s2 , s ); tmp = len1; len1 = len2; len2 = tmp; } memset( ss , '0' , sizeof( ss ) ); for( i=len2-1;i>=0;i-- ) { in = 0; memset( s , '0', sizeof( s ) ); for( j=len1-1;j>=0;j-- ) { x = s1[ j ] - '0'; y = s2[ i ] - '0'; if( ( x*y+in) >= 10 ) { s[ i+j ] = ( char )(( (x*y+in)%10 )+'0'); in = (x*y+in)/10; } else if( (x*y+in )<=9 && (x*y+in ) >=0 ) { s[ i+j ] =(char) (x*y+in +'0'); in = 0; } }if( in != 0 && i!=0 ) s[ i-1 ] = in+'0'; flag = 0; for( j=i+len2-1;j>=0;j-- ) { if( ss[ j ]-'0' + s[ j ] -'0' + flag >=10 ) { ss[ j ] = (ss[ j ]-'0' + s[ j ] - '0' + flag )%10+'0'; flag = 1; } else { ss[ j ] += s[ j ] -'0'+ flag; flag = 0; } }if( i == 0 && in+flag )printf("%d",in+flag); } ss[ len1+len2-1 ] = '\0'; len = strlen( ss ); for(i=0;i<len;i++) if( !flag && ss[ i ] == '0' ) continue; else { printf("%c",ss[ i ]); flag = 1; } if( !flag ) printf("0"); puts(""); } return 0;}
2 0
- UVA 10106 乘积
- UVa 10106 乘积
- UVa 10106 乘积
- 最大乘积 Uva 11059
- 最大乘积 Uva 11059
- UVa 11059 最大乘积
- UVa 11059 最大乘积(水)
- 最大乘积(Maximum Product,UVA 11059)
- UVa 11059 最大乘积(枚举)
- 例题7-2 最大乘积 UVa 11059
- 最大乘积(Maximum Product,UVa 11059)
- 最大乘积(Maximum Product,UVA 11059)
- UVa 11509 Maximum Product(最大乘积)
- UVA 11059 Maximum Product 最大乘积
- 最大乘积(Maximum Product, UVa 11059)
- UVa 11059----Maximum Product(最长上升子序列乘积)
- UVA 11542 Square 乘积是平方数(高斯消元)
- UVA 11059 Maximum Product最大乘积(暴力法)
- win8 驱动签名
- USACO月赛题解 第三十讲 动态规划(一)
- 开源编译器学习笔记05(VC6 语法分析器——见面语法树状态机)——2014_2_1
- 类和对象部分练习
- 利用q解决嵌套回调的问题
- UVa 10106 乘积
- JQuery中常用方法备忘
- Leetcode: Insert Interval
- Windows 8.1 IE11 打不开 无法启动 解决方法
- 《浅谈用极大化思想解决最大子矩形问题》
- 动态规划4:最大子段和问题到最大子矩阵问题(四):最大子矩阵面积问题
- C/C++ 程序的入口选择
- Oracle学习笔记(2)—— 解锁用户 unlock user
- 三维向量叉乘推导