Times17--高精度
来源:互联网 发布:黑客用函数语言编程 编辑:程序博客网 时间:2024/05/17 04:50
题意:二进制的高精度与低精度乘法
分析:通过17的二进制表示,我们发现,只有两位1,所以可以用类似大整数加法的方法来处理。第几位有1,就相当于把输入的二进制右移几位。存储的时候,记得倒过来存。
Code:
#include <cstdio>#include <cstring>using namespace std;const int maxn = 1005;char s[maxn];int a[maxn], b[maxn];int ans[maxn];int main() {while(scanf("%s", s) != EOF) {memset(a, 0, sizeof(a));memset(b, 0, sizeof(b));int len = strlen(s);for(int i = 0; i < len; i++)a[i] = s[len-i-1]-'0';for(int i = 4; i < len+4; i++)b[i] = s[len+4-i-1]-'0';int carry = 0;for(int i = 0; i < len+4; i++) {int tmp = a[i]+b[i]+carry;ans[i] = tmp%2;carry = tmp/2;}int cnt = len+4;if(carry != 0) ans[cnt++] = 1;for(int i = cnt-1; i >= 0; i--)printf("%d", ans[i]);printf("\n");memset(s, 0, sizeof(s));}return 0;}
0 0
- Times17--高精度
- Sicily 6084 Times17
- Sicily 6084. Times17
- sicily 6084 Times17
- 17倍(Times17)
- 8.9 17倍times17 2492
- 高精度
- 高精度
- 高精度
- 高精度。。
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 高精度
- 集成Cordova+crosswalk with Android
- iOS8统一的系统提示控件——UIAlertController
- CXF+Spring 发布SOAP服务
- Linux tail命令
- 程序员的春天来了,赏花去!说走就走
- Times17--高精度
- Ant 设置代理服务器
- Android报错:java.lang.NumberFormatException: Invalid int: "15112340003"
- 一笔画问题 nyoj42
- iOS 百度地图当前位置方向问题解决方案
- php常用的一些函数
- java设计模式——结构型之适配器模式
- 通过一个大型项目来学习分布式算法(2)
- ListView在显示较少数据是,高度由item的个数决定,wrap_content有效