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 ;
}
1010. Radix (25)(未完成)的更多相关文章
- PAT 解题报告 1010. Radix (25)
		1010. Radix (25) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 11 ... 
- 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 ... 
- pat 甲级 1010. Radix (25)
		1010. Radix (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given a pair of ... 
- 已经菜到不行了 PAT 1010. Radix (25)
		https://www.patest.cn/contests/pat-a-practise/1010 题目大意: 输入四个数字,a,b,c,d. a和b是两个数字,c=1表示是第一个数字,c=2表示是 ... 
- 1010. Radix (25)
		Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ... 
- PAT (Advanced Level) 1010. Radix (25)
		撸完这题,感觉被掏空. 由于进制可能大的飞起..所以需要开longlong存,答案可以二分得到. 进制很大,导致转换成10进制的时候可能爆long long,在二分的时候,如果溢出了,那么上界=mid ... 
- 1010. Radix (25) pat
		Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ... 
- 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 ... 
- 1010. Radix (25)(出错较多待改进)
		Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ... 
随机推荐
- PAT——乙级真题1001代码
- Java总结——文件&流
			最近学习了Java的输入输出,脑子里有两点乱,不过比之前的思路好像清晰了很多.脑子刚刚接收这些信息的时候,整个就是懵逼的,又是文件又是流的,文件到底干嘛的,流到底干嘛的?恩,后来,想了想,其实也不难理 ... 
- CCNET+MSBuild+SVN实现每日构建
			最近开始将源代码迁移到SVN,于是便考虑到如何从SVN定期获取源码,自动编译并部署以减轻工作量并提高工作效率.通过多方搜集资料并进行研究,基本实现了这个功能.对于每日构建的概念就不具体展开了,可以在各 ... 
- 一个简单的c# 贪吃蛇程序
			一个简单的c#贪吃蛇程序 程序分为界面设计和程序设计:界面设计和程序设计均参考了一些游戏实例,但是所有代码内容是本人编写. 由于看到别人写的程序并没有署名,这里的署名全部都是csdn官网. 游戏界面设 ... 
- Djunit工作记录Mock时出现为null的情况setReturnValueAt|MockObjectManager.addReturnValue不起作用
			最近工作要对代码进行局部测试并编写测试文档,可是偶的环境还没搞好哦(开始不太乐意直接请教前辈,还是选择自己先搞一下了)经过电脑重装jdk ,eclipse,djunit工具包ver***,等等确定不是 ... 
- 夺命雷公狗----Git---5---分支
			git分支的概念相当于是添加一个属于自己的分支,别人是看不到的,等你写完自己的程序到时候在合并到团队的分支上即可.... 我们可以查看自己git里面有什么分支,如下所示: git branch 在这里 ... 
- SecureCRT:保存输出日志的方法
			处理地址: http://blog.sina.com.cn/s/blog_64c1dd210101gzgz.html 或者: http://renchen.blog.51cto.com/4531967 ... 
- Entity Framework7 入门之全功能.NET版本下使用EF7(含源码)另附数据迁移常见错误处理
			Entity Framework7 入门之全功能.NET(Console, WinForms, WPF等)使用EF7 昨天,我们介绍了EF的新特性和开发计划,如果你还不了解,请移步 Entity Fr ... 
- 在jasp页面循环显示
			<% int h=3;//行数 int l=3;//列数 %> <table> <% for(int i=0;i<h;i++){ %> <tr> ... 
- 鸟哥的linux私房菜学习记录之软件安装原始码与Tarball
