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 ...
随机推荐
- VSO-Branch和Merge
分支策略 一般采用一个MAIN分支,一个或多个DEVELOPMENT分支的分支结构,如下图(来自:https://msdn.microsoft.com/en-us/library/ee782536.a ...
- (转)SVN服务器搭建和使用(一)
Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上了,下载地址: http:// ...
- 网页3D引擎“Babylon.JS”入门教程翻译总结
使用三个月的业余时间把官方教程的入门部分译为中文并上传到github,在下一步编程前做一个总结. 历程: 最早接触游戏编程是在大三下学期,用汇编语言和实验室里的单片机.触摸屏.电机(提供声效)编的打地 ...
- Hosts文件
Hosts是一个没有扩展名的系统文件,可以用记事本等工具打开, 其作用:就是将一些常用的网址域名与其对应的IP地址建立一个关联"数据库",当用户在浏览器中输入一个需要登录的网址时, ...
- Activityn 生命周期
前言 Activity 生命周期,虽然开发android 程序有几年了,但是很多基本东西还是经常遗忘模糊,在此笔记白纸黑字记录,下次记忆模糊的时候温故知新.网上一搜索一大把,但是多是一大堆各种日志搅来 ...
- Google Code Jam Round 1A 2015 解题报告
题目链接:https://code.google.com/codejam/contest/4224486/ Problem A. Mushroom Monster 这题题意就是,有N个时间点,每个时间 ...
- 一些CSS
/*自定义*白烟*文本/边框/背景色*/ .text-whitesmoke,a.text-whitesmoke:link,a.text-whitesmoke:visited,.button.borde ...
- HashSet的故事----Jdk源码解读
Hash,我们在说HashMap的时候,已经知道Hash是散列,Map是映射了. 那么Set又是什么呢 ? 先来看看Set的翻译是什么 n. [数] 集合:一套:布景:[机] 装置 这里Set所取的含 ...
- Office2010安装错误1402问题(我安装成功了)
转载:http://blog.sina.com.cn/s/blog_555ea2470101831d.html 做个记录. 1.卸载OFFICE 使用工具 MicrosoftFixit,Window ...
- 当java出现异常,应如何进行处理
Java异常是一个描述在代码段中发生的异常(也就是出错)情况的对象.当异常情况发生,一个代表该异常的对象被创建并且在导致该错误的方法中被抛出(throw).该方法可以选择自己处理异常或传递该异常.两种 ...