Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is "yes", if 6 is a decimal number and 110 is a binary number.

Now for any pair of positive integers N1 and N2, your task is to find the radix of one number while that of the other is given.

Input Specification:

Each input file contains one test case. Each case occupies a line which contains 4 positive integers:
N1 N2 tag radix
Here N1 and N2 each has no more than 10 digits. A digit is less than
its radix and is chosen from the set {0-9, a-z} where 0-9 represent the
decimal numbers 0-9, and a-z represent the decimal numbers 10-35. The
last number "radix" is the radix of N1 if "tag" is 1, or of N2 if "tag"
is 2.


Output Specification:

For each test case, print in one line the radix of the other number
so that the equation N1 = N2 is true. If the equation is impossible,
print "Impossible". If the solution is not unique, output the smallest
possible radix.

Sample Input 1:

6 110 1 10

Sample Output 1:

2

Sample Input 2:

1 ab 1 2

Sample Output 2:

Impossible

现在是只能拿18分,感觉自己题意理解的有问题,过几天再看看吧,今天实在是看不下去了....

#include <iostream>
#include <cmath>
#include <cstring> using namespace std; long long int translate(string a,int r){
long long int a10=;
int x;
int n=a.length();
int c=;
for(int i=n-;i>=;i--){
if(a[i]>)
x=a[i]-;
else{
x=a[i]-;
}
a10=a10+x*pow(r,c);
c++;
}
return a10;
} int main()
{
string a,b;
long long int a10=,b10=;
int n,r;
int flag=;
cin>>a>>b>>n>>r;
if(n==){
a10=translate(a,r);
int i;
if(b.length()==) i=translate(b,)+;
else i=;
for(;i<;i++){
if(translate(b,i)==a10){
cout<<i<<endl;
flag=;
break;
} }
if(flag==)
cout<<"Impossible"<<endl; }
else if(n==){
b10=translate(b,r);
int i;
if(a.length()==) i=translate(a,)+;
else i=;
for(;i<;i++){
if(translate(a,i)==b10){
cout<<i<<endl;
flag=;
break;
} }
if(flag==)
cout<<"Impossible"<<endl;
}
return ;
}

最新文章

  1. BFC给我的帮助以及对hasLayout的认识
  2. 深入理解javascript函数系列第三篇——属性和方法
  3. 在公司内网上创建自己的 OSM.Planet 街道级别地图服务器及其客户端程序
  4. 《oracle每天一练》Oracle冷备份与数据恢复
  5. Adaboost算法初识
  6. css 单位转换
  7. RTP协议分析(转自:http://blog.csdn.net/bripengandre/article/details/2238818)
  8. [转]Reducing script compile time or a better workflow to reduce excessive recompiling
  9. jQuery 事件 - error() 方法
  10. js日期天数差
  11. node.js基础:HTTP服务器
  12. 在Caffe添加Python layer详细步骤
  13. [1] MVC &amp; MVP &amp;MVVM
  14. Dynamics CRM 插件注册时报Assembly must be registered in isolation的解决方法
  15. Python高阶函数和匿名函数
  16. 通过SID查找历史执行的SQL语句
  17. Linux下tar压缩解压缩命令详解
  18. php7 php-fpm 重启
  19. study design of ADNI
  20. cent os 6.5 配置vsftpd

热门文章

  1. Node.js 安装与配置
  2. 用Canvas制作简单的画图工具
  3. 图片轮播器bcastr4.swf“&amp;”符号的问题
  4. 如何写出优雅的Python(二)
  5. Immutable笔记
  6. 一周试用yii开发一个带各种该有功能的web程序(三)
  7. [综合]visio2013安装提示找不到Office.zh_cn\officeMUI.mis officemui.xml
  8. Spring学习笔记之一----基于XML的Spring IOC配置
  9. Highcharts使用教程(2):设置选项
  10. CSS、HTML5、JS