Advertisement
Negru_Diana

baze 2014

Dec 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. using namespace std;
  4. ifstream fin("baze.in");
  5. ofstream fout("baze.out");
  6. int main()
  7. {
  8. int n, k, t, maxim=0, b, pb, ok=0, x10, cifra;
  9. fin>>n;
  10. int aux=n;
  11. while(aux)
  12. {
  13. if(aux%10>maxim)
  14. {
  15. maxim=aux%10;
  16. }
  17. aux=aux/10;
  18. }
  19. for(b=maxim+1; b<=10; b++)
  20. {
  21. x10=0;
  22. aux=n;
  23. int og=0;
  24. pb=1;
  25. while(aux)
  26. {
  27. int cifra=aux%10;
  28. x10=x10+cifra*pb;
  29. pb=pb*b;
  30. aux=aux/10;
  31. }
  32. aux=x10;
  33. while(aux)
  34. {
  35. og=og*10+aux%10;
  36. aux=aux/10;
  37. }
  38. if(og==x10)
  39. {
  40. ok=1;
  41. break;
  42. }
  43. }
  44. x10=0;
  45. pb=1;
  46. if(ok==1)
  47. {
  48. fout<<b;
  49. }
  50.  
  51. else
  52. {
  53. while(n)
  54. {
  55. cifra=n%10;
  56. x10=x10+cifra*pb;
  57. pb*=maxim+1;
  58. n=n/10;
  59.  
  60. }
  61. fout<<x10;
  62. }
  63.  
  64. fin.close();
  65. fout.close();
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement