uva 748 - Exponentiation 带小数点的大数乘法
来源:互联网 发布:mac队 编辑:程序博客网 时间:2024/05/09 22:50
实数的大数乘法 就多一个定位小数点 输出的时候不输出前导和后导零 所以大数乘法模版很重要
下面直接上代码
#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespace std;int point;//小数点的最终位置int zero(char *l)//控制后导零不输出{ int i; for(i = 0; l[i]=='0' ;i++); return i;}void print(char *p, int p_len){ char str[200],str_len = 0; for(int i = 0;i < p_len; i++) { if(i == point)str[str_len++] = '.';//补上小数点 str[str_len++] = p[i]; } int i = str_len-1; for(i = str_len-1; str[i] == '0'; i--);//加上这条输出时去掉前导零 for( ;i >= zero(str); i--) printf("%c",str[i]); printf("\n");}int re_order(char *p, int p_len, char *q)//逆序存储p到q中{ int q_len = 0; for(int i = p_len-1; i >= 0; i--) { if(p[i] == '.')continue;//去掉小数点 q[q_len++]=p[i]; } q[q_len]='\0'; return q_len;}void multi(char *p, int p_len, int N){ char str[200]; int num[200],i, j, t; int str_len = p_len,sum; strcpy(str,p); for(t = 0; t < N-1; t++)//N个数相乘 { sum = 0; memset(num,0,sizeof(num));//这一定要初始化为零 要不容易Wrong的 for(i = 0; i < p_len; i++) for(j = 0; j < str_len; j++) num[i+j] += (p[i]-'0')*(str[j]-'0'); for(i = 0; i < p_len+str_len; i++) { sum += num[i]; str[i] = sum%10+'0'; sum /= 10; } str_len = i; str[i]='\0'; } print(str,str_len);}int main(){ #ifdef LOCAL freopen("in1.txt","r",stdin); #endif // LOCAL char str[10],s[10]; int N; while(scanf("%s%d\n",str,&N)!=EOF) { int str_len = strlen(str); for(int i = 0; i < str_len; i++) if(str[i] == '.'){point = (str_len -i -1)*N;break;} int s_len = re_order(str, str_len, s); multi(s,s_len,N); } return 0;}
- uva 748 - Exponentiation 带小数点的大数乘法
- 大数乘法 748 - Exponentiation
- UVA 748 Exponentiation 高精度乘法
- uva 748 Exponentiation(高精度实数乘法)
- hdu 1063 Exponentiation 大数乘法
- HDU 1063 Exponentiation(大数乘法)
- POJ 1001 Exponentiation 无限大数的指数乘法 题解
- poj 1001 uva 748 Exponentiation(高精度小数乘法)
- POJ 1001 Exponentiation (高精度/大数乘法)
- POJ 1001 Exponentiation 大数乘法模拟
- [ACM Steps]2.3.2 Exponentiation 大数乘法 小数的n次幂
- UVa 748 Exponentiation
- UVa OJ 748-Exponentiation
- uva 748 - Exponentiation
- UVA 试题 748 - Exponentiation
- UVa 748 - Exponentiation
- UVa 748 - Exponentiation
- UVa 748Exponentiation
- 工具栏的显示和隐藏
- 打开RabbitMQ管理界面的注意点
- acmclub 2081 班级聚会上的游戏
- 【操作系统面试专题】:何谓死锁?产生死锁的原因和必要条件是什么?
- 记录一次mysql链接ERROR 2003错误
- uva 748 - Exponentiation 带小数点的大数乘法
- C++中的递归过程
- JDK环境变量配置
- 【操作系统面试专题】:分页和分段存储管理有何区别?
- 老码农教你学英语
- 如何制作优秀的PPT
- Derby使用1—初识
- poj 2260 Error Correction
- CC2530 RF部分使用 ——实现点对点收发