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