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. lua的table排序
  2. ch4 MySQL 安全管理
  3. 2016年6月27日 星期一 --出埃及记 Exodus 14:24
  4. 在 CentOS 上安装和配置 OpenNebula
  5. 【HDOJ】1728 逃离迷宫
  6. (转)xcode报Could not find a storyboard named...错误的解决办法
  7. 关于web标准的理解(转)
  8. js秒数转换时分秒方法
  9. Python3 词汇助手 有道翻译助手 有道导出文件格式转换
  10. 201621123040《Java程序设计》第七周学习总结
  11. Travel 并查集
  12. Java对象引用和对象赋值
  13. Python基础(六) python生成xml测试报告
  14. Vue2.0增删改查案例(Vue+Less+LocalStorage)
  15. windows下git 同步数据到github的常见问题
  16. Charles设置HTTPS抓包
  17. 李白打酒——C++
  18. 【随笔】Android应用市场搜索优化(ASO)
  19. Unix/Linux系统管理技术手册学习笔记——shell
  20. leetcode925

热门文章

  1. Dll的生成,转化为OMF格式的DLL
  2. FusionCharts饼图的图例属性
  3. ZOJ-1239 Hanoi Tower Troubles Again!
  4. sql语句修改字段长度
  5. rdesktop共享剪贴板的问题
  6. quick-cocos2d-x :加入精灵背景
  7. zabbix
  8. Warning: Using a password on the command line interface can be insecure.解决办法
  9. 搜索引擎LuceneNet
  10. 09B-独立按键消抖实验02——小梅哥FPGA设计思想与验证方法视频教程配套文档