Advertisement
a53

iepuras2

a53
Jun 16th, 2021
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("iepuras.in");
  5. ofstream fout("iepuras.out");
  6. int n, C;
  7. long long nr, nmax, nmin, aux, nrap, p;
  8. long long numar_mare(long long x)
  9. {
  10. int frm[10];
  11. for(int c=0; c<10; ++c)
  12. frm[c]=0;
  13. long long mare=0;
  14. do
  15. {
  16. frm[x%10]=1;
  17. x/=10;
  18. }while(x);
  19. for(int c=9; c>=0; --c)
  20. if(frm[c])
  21. mare=mare*10+c;
  22. return mare;
  23. }
  24. long long numar_mic(long long x)
  25. {
  26. int frc[10], ok=0;
  27. long long mic=0;
  28. for(int c=0; c<10; ++c)
  29. frc[c]=0;
  30. do
  31. {
  32. frc[x%10]=1;
  33. if(x%10==0)
  34. ok=1;
  35. x/=10;
  36. }while(x);
  37. if(ok)
  38. {
  39. int c=1;
  40. while(frc[c]==0)
  41. c++;
  42. mic=c;
  43. frc[c]=0;
  44. }
  45. for(int c=0; c<10; ++c)
  46. if(frc[c])
  47. {
  48. mic=mic*10+c;
  49. frc[c]=0;
  50. }
  51. return mic;
  52. }
  53. int main()
  54. {
  55. fin>>C;
  56. if(C==1)
  57. {
  58. fin>>n;
  59. for(int i=1; i<=n; ++i)
  60. {
  61. fin>>nr;
  62. nmax=numar_mare(nr);
  63. nmin=numar_mic(nr);
  64. fout<<(nmax+nmin)<<'\n';
  65. }
  66. return 0;
  67. }
  68. fin>>n;
  69. for(int i=1; i<=n; ++i)
  70. {
  71. fin>>nr;
  72. aux=nr;
  73. p=1;
  74. nrap=0;
  75. long long alt=0;
  76. int cifc=(aux%9==0 ? 9 : aux%9);
  77. do
  78. {
  79. if(cifc<(nr % 10)) nrap=nrap+((nr / 10)+1)*p;
  80. if (cifc>(nr % 10)) nrap=nrap+(nr / 10)*p;
  81. if (cifc==(nr % 10)) nrap=nrap+((nr / 10)*p)+alt+1;
  82. alt=alt+(nr % 10)*p;
  83. nr=nr / 10;
  84. p=p*10;
  85. } while(nr>0);
  86. fout<<nrap<<'\n';
  87. }
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement