Sicily 6084. Times17
来源:互联网 发布:阿里云总部 良渚 编辑:程序博客网 时间:2024/06/06 08:59
After realizing that there is much money to be made in software development, Farmer John has launched a small side business writing short programs for clients in the local farming industry. Farmer John's first programming task seems quite simple to him -- almost too simple: his client wants him to write a program that takes a number N as input, and prints 17 times N as output. Farmer John has just finished writing this simple program when the client calls him up in a panic and informs him that the input and output both must be expressed as binary numbers, and that these might be quite large. Please help Farmer John complete his programming task. Given an input number N, written in binary with at most 1000 digits, please write out the binary representation of 17 times N.
* Line 1: The binary representation of N (at most 1000 digits).
* Line 1: The binary representation of N times 17.
10110111
110000100111
// Problem#: 6084// Submission#: 3667523// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/// All Copyright reserved by Informatic Lab of Sun Yat-sen University#include<iostream>#include<string>#include<cstring>#include<cstdio>#include<cctype>#include<algorithm>#include<cmath>#include<climits>#include<stack>#include<vector>using namespace std;int main(){ string n_binary; cin>>n_binary; string result_binary=n_binary+"0000"; n_binary="0000"+n_binary; int len=result_binary.length(); int temp=0; for(int i=len-1;i>0;i--){ if((n_binary[i]-'0')+(result_binary[i]-'0')+temp<2){ result_binary[i]=(n_binary[i]-'0')+(result_binary[i]-'0')+temp+'0'; temp=0; } else{ result_binary[i]=(n_binary[i]-'0')+(result_binary[i]-'0')+temp+'0'-2; temp=1; } } if(temp==1){ result_binary[0]='0'; result_binary="1"+result_binary; } cout<<result_binary<<endl; return 0;}
#include<iostream>using namespace std;int main(){ string n_binary; cin>>n_binary; string result_binary=n_binary+"0000";//乘以17可以先乘上16在加上本身 n_binary="0000"+n_binary;//补足位数进行模拟手算 int len=result_binary.length(); int temp=0;//记录进位 for(int i=len-1;i>0;i--){//模拟手算加法 if((n_binary[i]-'0')+(result_binary[i]-'0')+temp<2){//不够进位 result_binary[i]=(n_binary[i]-'0')+(result_binary[i]-'0')+temp+'0'; temp=0; } else{ result_binary[i]=(n_binary[i]-'0')+(result_binary[i]-'0')+temp+'0'-2; temp=1; } } if(temp==1){//如果最高位有进位需要在前面补'1',而进位之后第二位变为'0' result_binary[0]='0'; result_binary="1"+result_binary; } cout<<result_binary<<endl; return 0;}
- Sicily 6084. Times17
- Sicily 6084 Times17
- sicily 6084 Times17
- Times17--高精度
- 17倍(Times17)
- 8.9 17倍times17 2492
- Sicily 1027
- sicily 1007
- sicily 1795
- sicily 1036
- sicily 1419
- sicily 1889
- sicily 1684
- sicily 1686
- sicily 1004
- sicily 1135
- sicily 1152
- sicily 1151
- 黑马程序员_基础篇(根据老师笔记自定简化版)
- 经典算法题一览
- 【android开发】 Unable to resolve target 'android-4'
- 邮件原理与JavaMail开发中应用的一些重要的类
- ios AFN相关知识
- Sicily 6084. Times17
- Javaweb学习笔记10—文件上传与下载
- Windows内核中使用List链表来模拟FIFO操作
- 正则表达式
- 黑马程序员_基础篇(自定义笔记)_02
- Java之断点调试小记
- Ubuntu下QT安装Opencv库
- 链表笔记
- JAVA学习笔记(五十一)- DBUtil 封装数据库工具类