Advertisement
FazEN

Untitled

Mar 17th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include<iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. void x(int *a)
  6. {
  7.  
  8. int i1=0;
  9. int f1=*a;
  10. int s1=0;
  11. int c1=0;
  12. int a3=*a;
  13. int f=*a;
  14. while (*a!=0)
  15. {
  16.  
  17. ++i1;
  18. c1=*a%10;
  19. *a/=10;
  20.  
  21. }
  22.  
  23.  
  24. do
  25. {
  26. int k=pow(10,i1);
  27. s1+=f1/k;
  28. f1%=k;
  29.  
  30. --i1;
  31. } while (i1!=0);
  32. int a2=s1+f%10;
  33. int a1=a2/10+a2%10;
  34. if (a1>10) {
  35. a1/=2;
  36. a2-=a1;
  37. }
  38. else {
  39.  
  40.  
  41. if (a1==a2 && a1) {
  42. *a=a3+a1;
  43. }else {
  44. *a=a3+a2+a1;
  45.  
  46. }
  47. }
  48.  
  49. }
  50.  
  51. int main() {
  52.  
  53.  
  54. int b=0;
  55. cin>>b;
  56. if (b<10)
  57. {
  58. cout<<b;
  59. }
  60. else if (b<=10)
  61. {
  62. cout<<-1;
  63. }else
  64. {
  65.  
  66. for (int i=b;i>=floor(b/1.5);--i)
  67. {
  68. int g=i;
  69. x(&g);
  70.  
  71.  
  72. if (g==b)
  73. {
  74. cout<<i;
  75. break;
  76. }
  77. else if (i==floor(b/1.5) && g!=b)
  78. {
  79. cout<<-1;
  80. break;
  81. }
  82. }
  83. }
  84.  
  85. return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement