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 ;
}

1010. Radix (25)(未完成)的更多相关文章

  1. PAT 解题报告 1010. Radix (25)

    1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ...

  2. PAT 甲级 1010 Radix (25)(25 分)进制匹配(听说要用二分,历经坎坷,终于AC)

    1010 Radix (25)(25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 ...

  3. pat 甲级 1010. Radix (25)

    1010. Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of ...

  4. 已经菜到不行了 PAT 1010. Radix (25)

    https://www.patest.cn/contests/pat-a-practise/1010 题目大意: 输入四个数字,a,b,c,d. a和b是两个数字,c=1表示是第一个数字,c=2表示是 ...

  5. 1010. Radix (25)

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...

  6. PAT (Advanced Level) 1010. Radix (25)

    撸完这题,感觉被掏空. 由于进制可能大的飞起..所以需要开longlong存,答案可以二分得到. 进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid ...

  7. 1010. Radix (25) pat

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...

  8. 1010 Radix (25)(25 point(s))

    problem Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true ...

  9. 1010. Radix (25)(出错较多待改进)

    Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...

随机推荐

  1. Nodejs的Express完成安装指导

    一.安装 官网http://expressjs.com/ express4.X的有一些变化,4.x版本中将命令工具单独分出来了(https://github.com/expressjs/generat ...

  2. Python 字符串反转

    方法一: 切片的方法 a = "hello"b = len(a)i = 1c = ""while i<=b: d = a[b-i] c += d i+=1 ...

  3. web前端基础知识 jQuery

    通过之前的学习我们已经了解了html.css.javascript的相关知识:本次我们就共同学习进阶知识:jQuery~ 一.什么是jQuery? jQuery其实就是一个轻量级的javascript ...

  4. JavaWeb-springMVC

    <context:component-scan/> 扫描指定的包中的类上的注解,常用的注解有: @Controller 声明Action组件@Service    声明Service组件  ...

  5. ListView遍历每个Item出现NullPointerException的异常

    在使用ListView过程中我们有时候需要遍历取得每个Item项中的一些数据(比如每个Item里面有TextView,需要获取它的文本等等),但是我们在遍历过程中经常会遇到NullPointerExc ...

  6. Qt之添加QLabel的点击事件

    QLabel功能为显示了一个字符串或者图片等信息,它本身没有click信号.也就不能够响应click点击事件,有什么办法来实现来,我们可以子类化QLabel,实现MouseXXXEvent.class ...

  7. qt qml qchart 图表组件

    qt qml qchart 图表组件 * Author: Julien Wintz * Created: Thu Feb 13 23:41:59 2014 (+0100) 这玩意是从chart.js迁 ...

  8. PhpStorm创建Drupal模块项目开发教程(3)

    rush是 Drupal的脚本界面,PhpStorm的命令行工具支持Drush 5.8和更高版本. 接下来就Drush配置和基本操作进行设置,首先点击打开Settings | Command Line ...

  9. mybatis研究:select性能对比

    package sss.mybatis_1; import java.io.InputStream; import java.security.Principal; import java.util. ...

  10. RabbitMQ高可用方案总结

    RabbitMQ的集群方案有以下几种: 1.普通的集群 exchange,buindling再所有的节点上都会保存一份,但是queue只会存储在其中的一个节点上,但是所有的节点都会存储一份queue的 ...