PAT 1010 Radix(X)
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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 500 vector<char> vec; map<char,int> mp; ll tansss(string s,int x){
ll sum = ;
ll t = ;
for(int i=s.size()-;i>=;i--){
sum += mp[s[i]]*t;
t *= x;
}
return sum;
} int main(){
for(int i=;i <= ;i++){
vec.push_back(char(''+i));
}
for(int i=;i <= ;i++){
char temp = char('a'+(i-));
vec.push_back(temp);
} for(int i=;i < vec.size();i++){
mp[vec[i]] = i;
} // while(1){
// string s; cin >> s;
// int radix; cin >> radix;
// cout << tansss(s,radix);
// } string s1,s2;
int tag,radix;
cin >> s1 >> s2 >> tag >> radix; if(tag == ){
ll ok = tansss(s1,radix);
for(int i=;i<=;i++){
if(tansss(s2,i)==ok){
cout << i;
return ;
}
}
cout << "Impossible";
}
else{
ll ok = tansss(s2,radix);
for(int i=;i<=;i++){
if(tansss(s1,i)==ok){
cout << i;
return ;
}
}
cout << "Impossible";
} return ;
}
还要判断溢出。。。打扰了拿16分溜了
最新文章
- 基于trie树的具有联想功能的文本编辑器
- html、canvas、视频灰度、反色
- 详解Android中AsyncTask的使用
- 使用CocoaPod导入Swift第三方库报错
- Head First Html and CSS学习笔记之HTML
- hdu 4001 dp 2011大连赛区网络赛A
- spring源码学习【准备】之jdk动态代理和cglib动态代理的区别和性能
- SSRS入门相关笔记
- Project Euler 109 :Darts 飞镖
- 关于SQL Server中分区表的文件与文件组的删除(转)
- Android v4 包和v7包问题
- php内存管理
- Shoot the Bullet
- 当前项目与当前环境的JDK版本不匹配”Bad version number in .class file“
- 当向计算机中存入一个float类型的数值2.2 后,在从计算机中读出输出,这时2.2 的值已经发生了变化(转)
- 线性代数之行列式的C#研究实现
- Java自己动手写连接池二
- C51汇编典型代码&;一些org-mode技巧
- Git秘钥生成以及Gitlab配置(附以下问题解决方法:Key is invalid Fingerprint cannot be generated)
- Python之队列Queue
热门文章
- [CSP-S模拟测试41]题解
- IE11“__doPostBack”未定义”
- 【从0到1,搭建Spring Boot+RESTful API+Shiro+Mybatis+SQLServer权限系统】06、Mybatis+SQLServer集成
- 93、R语言教程详解
- webstorm 分屏
- PAT甲级——A1149DangerousGoodsPackaging【25】
- Oracle启动或关闭归档模式
- 清除浮动最有效的css写法
- docker--删除container和image
- 装完某些软件之后IE主页被https://www.hao123.com/?tn=93453552_hao_pg劫持