Advertisement
Saleh127

UVA 343

Nov 12th, 2020
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5.  
  6. ll deshimal(char a[],ll base,ll len)
  7. {
  8. ll ans=0,c=1,i;
  9.  
  10. for(i=len-1; i>=0; i--)
  11. {
  12. if(a[i]>='0' && a[i]<='9')
  13. {
  14. ans+=(a[i]-'0')*c;
  15. }
  16. else ans+=(a[i]-'A'+10)*c;
  17.  
  18. c*=base;
  19. }
  20. return ans;
  21. }
  22.  
  23.  
  24. int main()
  25. {
  26. ios_base::sync_with_stdio(0);
  27. cin.tie(0);
  28. cout.tie(0);
  29.  
  30. char a[1000],b[1000];
  31.  
  32. while(scanf("%s %s", a, b) == 2)
  33. {
  34.  
  35. ll l1=strlen(a);
  36. ll l2=strlen(b);
  37.  
  38. ll b1=1,b2=1,i,j,k=0,l; ///b1,b2 = bases
  39.  
  40. for(i=0; i<l1; i++)
  41. {
  42. if(a[i]>='0' && a[i]<='9')
  43. {
  44. if((a[i]-'0')>b1)
  45. {
  46. b1=a[i]-'0';
  47. }
  48. }
  49. else
  50. {
  51. if((a[i]-'A'+10)>b1)
  52. {
  53. b1=a[i]-'A'+10;
  54. }
  55. }
  56. }
  57.  
  58. for(i=0; i<l2; i++)
  59. {
  60. if(b[i]>='0' && b[i]<='9')
  61. {
  62. if((b[i]-'0')>b2)
  63. {
  64. b2=b[i]-'0';
  65. }
  66. }
  67. else
  68. {
  69. if((b[i]-'A'+10)>b2)
  70. {
  71. b2=b[i]-'A'+10;
  72. }
  73. }
  74. }
  75.  
  76. b1++;
  77. b2++;
  78.  
  79. for(i=b1; i<=36; i++)
  80. {
  81. for(j=b2; j<=36; j++)
  82. {
  83. if(deshimal(a,i,l1)==deshimal(b,j,l2))
  84. {
  85. printf("%s (base %d) = %s (base %d)\n",a,i,b,j);
  86. k=1;
  87. break;
  88. }
  89. }
  90. if(k) break;
  91. }
  92. if(k==0) printf("%s is not equal to %s in any base 2..36\n",a,b);
  93.  
  94. }
  95.  
  96. return 0;
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement