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分溜了
PAT 1010 Radix(X)的更多相关文章
- PAT甲组 1010 Radix (二分)
1010 Radix (25分) Given a pair of positive integers, for example, \(6\) and \(110\), can this equatio ...
- 1010 Radix (25 分)
1010 Radix (25 分) Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 1 ...
- PAT 1085 PAT单位排行(25)(映射、集合训练)
1085 PAT单位排行(25 分) 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤105),即考生人数.随 ...
- 7-07. PAT排名汇总(25) (结构体 ZJU_PAT)
题目链接:http://www.patest.cn/contests/ds/7-07 编程能力測试(Programming Ability Test,简称PAT)是浙江大学计算机科学与技术学院主办的专 ...
- PAT 1071 小赌怡情(15)(代码)
1071 小赌怡情(15 分) 常言道"小赌怡情".这是一个很简单的小游戏:首先由计算机给出第一个整数:然后玩家下注赌第二个整数将会比第一个数大还是小:玩家下注 t 个筹码后,计算 ...
- PAT 1058 选择题(20)(代码+思路)
1058 选择题(20 分) 批改多选题是比较麻烦的事情,本题就请你写个程序帮助老师批改多选题,并且指出哪道题错的人最多. 输入格式: 输入在第一行给出两个正整数 N(≤ 1000)和 M(≤ 100 ...
- PAT A1010 Radix (25 分)——进制转换,二分法
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
- PAT 1010 Radix (二分)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The an ...
- PAT 1010 Radix (25分) radix取值无限制,二分法提高效率
题目 Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The ...
随机推荐
- CDN技术详解(七)
动态内容加速服务的实现 随着Web2.0的兴起,产生了动态网页.个性化内容.电子交易数据等内容的加速,这些就涉及了动态内容加速技术. 静态内容的加速,都是对于表现层的加速,对于动态页面等内容的加速,则 ...
- 探索Redis设计与实现6:Redis内部数据结构详解——skiplist
本文转自互联网 本系列文章将整理到我在GitHub上的<Java面试指南>仓库,更多精彩内容请到我的仓库里查看 https://github.com/h2pl/Java-Tutorial ...
- http中请求协议 GET和POST两种基本请求方法的区别
GET和POST是什么?HTTP协议中的两种发送请求的方法. HTTP是什么?HTTP是基于TCP/IP的关于数据如何在万维网中如何通信的协议. HTTP的底层是TCP/IP.所以GET和POST的底 ...
- 筆記本 wifi走外网线 網卡走內網
筆記本 wifi走外网线 網卡走內網 ,案列 -------------------------------------------------------- route print ...
- Django基础篇(一)
Python的Web框架有Django.Tornado.Flask等多种,Django相较其他web框架的优势有: 大而全.框架本身集成了ORM框架.模板绑定.缓存.Session等诸多功能. 1.安 ...
- 网页打开qq
网页打开qq 打开qq方法tencent://message/?uin=”+“541239271”+“&Menu=yes http://wpa.qq.com/msgrd?V=1&uin ...
- MySQL-8.0填坑
Client does not support authentication protocol 或 Authentication plugin 'caching_sha2_password' cann ...
- upc组队赛12 Cardboard Container【枚举】
Cardboard Container Problem Description fidget spinners are so 2017; this years' rage are fidget cub ...
- 从Airbnb的发展历程和网易云的大起大落看IT行业创新(第5周课后作业)
我想先根据个人看法回答“创新是什么?”这个空泛的问题.创新是面对当下的资源条件限制创造出能够满足动态需求或解决动态发展中的问题的新策略.这种实用化定义在大部分邻域都勉强能让定义者自圆其说,对于IT行业 ...
- Process Array
http://xiaorui.cc/2016/05/10/%E6%BA%90%E7%A0%81%E5%88%86%E6%9E%90multiprocessing%E7%9A%84value-array ...