Codeforces Beta Round #46 (Div. 2)——B
来源:互联网 发布:mac nvm 安装nodejs 编辑:程序博客网 时间:2024/05/20 11:46
Vasya studies positional numeral systems. Unfortunately, he often forgets to write the base of notation in which the expression is written. Once he saw a note in his notebook saying a + b = ?, and that the base of the positional notation wasn’t written anywhere. Now Vasya has to choose a base p and regard the expression as written in the base p positional notation. Vasya understood that he can get different results with different bases, and some bases are even invalid. For example, expression 78 + 87 in the base 16 positional notation is equal to FF16, in the base 15 positional notation it is equal to 11015, in the base 10 one — to 16510, in the base 9 one — to 1769, and in the base 8 or lesser-based positional notations the expression is invalid as all the numbers should be strictly less than the positional notation base. Vasya got interested in what is the length of the longest possible expression value. Help him to find this length.
The length of a number should be understood as the number of numeric characters in it. For example, the length of the longest answer for 78 + 87 = ? is 3. It is calculated like that in the base 15 (11015), base 10 (16510), base 9 (1769) positional notations, for example, and in some other ones.
The first letter contains two space-separated numbers a and b (1 ≤ a, b ≤ 1000) which represent the given summands.
Print a single number — the length of the longest answer.
题意
求两个数和的最大长度。
思路:
找到每个数中最大的一个数字,比较大小,则所得数字加1之后的结果即是使结果(注意和为该进制下的和)最长的基数。
#include <cstdio>#include <algorithm>#include <iostream>#include <cmath>#define maxn 200using namespace std;int getmaxnum(int x)//找一个数字中最大数位{ int max=0; while(x) { int s=x%10; if(s>max) max=s; x/=10; } return max;}int change(int x,int base)//10进制转base进制{ int s=0,p=1; while(x) { s+=x%10*p; x/=10; p*=base; } return s;}int main(){ int a,b; cin>>a>>b; int base=max(getmaxnum(a),getmaxnum(b))+1;//求基数 int sum=change(a,base)+change(b,base);//在base进制下两数相加,求十进制结果 int j=0; while(sum)//求其位数 { int s=sum%base; sum/=base; j++; } cout<<j<<endl; return 0;}
- Codeforces Beta Round #46 (Div. 2)——B
- Codeforces Beta Round #96 (Div. 2)——B
- Codeforces Beta Round #93 (Div. 2 Only)——B
- Codeforces Beta Round #91 (Div. 2 Only)——B
- Codeforces Beta Round #89 (Div. 2)——B
- Codeforces Beta Round #18 (Div. 2 Only)——B
- Codeforces Beta Round #44 (Div. 2)——B
- Codeforces Beta Round #52 (Div. 2)——B
- Codeforces Beta Round #54 (Div. 2)——B
- CodeForces 581B Luxurious Houses(简单题)——Codeforces Beta Round #322 (Div. 2)
- Codeforces Beta Round #65 (Div. 2)——A,B,C
- Codeforces Beta Round #67 (Div. 2)——A,B,C
- Codeforces Beta Round #69 (Div. 2 Only)——A,B,D
- Codeforces Beta Round #70 (Div. 2)——A,B,C
- Codeforces Beta Round #72 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #73 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #76 (Div. 2 Only)——A,B,C
- Codeforces Beta Round #77 (Div. 2 Only)——A,B,C
- 文件路径资料
- 十二个让IT工作者过度劳累的坏习惯
- vs2008中tesseract配置
- Virtualbox虚拟机设置与主机的共享文件夹
- 判断ftp上文件是否存在
- Codeforces Beta Round #46 (Div. 2)——B
- [记录] XMPP协议的记录
- handlersocket使用 第二章 请求和回应
- 国内HTML5前端开发框架汇总
- nginx 反向代理及负载均衡
- Qt script 加载 js 的时机
- MSSQL自动备份数据库
- 设置ActionBar的颜色
- 国内免费(开源)CMS系统【大全】