【c++】PAT (Advanced Level)1010. Radix (25)
来源:互联网 发布:上古卷轴5enb优化 编辑:程序博客网 时间:2024/04/30 12:03
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 10Sample Output 1:
2Sample Input 2:
1 ab 1 2Sample Output 2:
Impossible
1.只有一位数的时候,取最小啊。2 18/25测试点还有几个
2。第二遍写 代码清晰了一点,但是还是没找出来测试点~
3.基数是可能超过35的
无聊给福利:
radix 测试点
答案为10 1 13 8 4分
答案为Impossible 14 17 18 2 7分
答案为 35 15 2分
答案为 2 6 2分
超过35 的 11 3 4 5 4分
#include <iostream>#include <iomanip>#include <string>using namespace std;int thenum(char a1){int cc;if(a1<='9'&&a1>='0'){cc=a1-'0';}else{cc=a1-'a'+10;}return cc;}int thesum(string a1,int radix){int n=a1.size(); int rr=1,b2=0;int b1=0;while(n--){b1=thenum(a1[n])*rr+b1;rr=rr*radix;}return b1;}int maxa(string a){int n=a.size(),max=0;for(int i=0;i<n;i++){int temp=thenum(a[i]);if(temp>max){max=temp;}}max++;if(max<2){max=2;}return max;}int main() {//freopen("in.txt","r",stdin);string N1,N2,a1,a2;int tag,radix;cin>>N1>>N2>>tag>>radix;if(tag==1){a1=N1,a2=N2;}else {a1=N2,a2=N1;}int b1,i;b1=thesum(a1,radix);int mm=maxa(a2);for(i=mm;i<=70;i++){if(i==radix)continue;if(b1==thesum(a2,i)){cout<<i;break;}}if(i==71){cout<<"Impossible";}system("pause");return 0;}
- 【c++】PAT (Advanced Level)1010. Radix (25)
- 【PAT Advanced Level】1010. Radix (25)
- PAT (Advanced Level) Practise 1010. Radix (25)
- 【PAT】【Advanced Level】1010. Radix (25)
- PAT (Advanced Level) Practise 1010. Radix (25)
- 1010. Radix (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) 1010. Radix (25) 进制匹配 二分法
- PAT (Advanced Level) Practise 1010. Radix (25) C++
- 浙大 PAT Advanced level 1010. Radix
- PAT (Advanced Level) Practise 1010Radix (25)
- PAT (Advanced) 1010. Radix (25)
- Pat(Advanced Level)Practice--1010(Radix)
- PAT (Advanced Level) Practise 1010 Radix
- 【C++】PAT(advanced level)1032. Sharing (25)
- 【C++】PAT(advanced level)1029. Median (25)
- 【C++】PAT(advanced level)1025. PAT Ranking (25)*
- 1010. Radix (25)-PAT
- 【PAT】1010. Radix (25)
- WebSphere7.0生成core文件和dump文件的方法
- The resource identified by this request is only capable of generating responses with characteristics
- 【简单数学】ZOJ 2975 Kinds of Fuwas
- nginx---stubstatus
- java算法买苹果
- 【c++】PAT (Advanced Level)1010. Radix (25)
- Vijos P1102 陶陶摘苹果
- 链表
- poj 2392--Space Elevator
- IEnumerator对象有什么呢?
- 关于PCB电路板中反面字符串信息如何才能正常显示的经验总结
- eclipse EL 表达式
- Call to master/192.168.41.134:9000 failed on connection exception: java.net.ConnectException: Conne
- spring hibernate