Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<math.h>
  4.  
  5. int getCount(int a)
  6. {
  7. int c=0;
  8. while(a!=0)
  9. {
  10. a=a/10;
  11. c++;
  12. }
  13. return c;
  14. }
  15.  
  16. int getNumber(int a,int k)
  17. {
  18. int c=getCount(a)-k;
  19. while(c!=0)
  20. {
  21. a=a/10;
  22. c--;
  23. }
  24. return a;
  25. }
  26.  
  27. int soc(int a,int b)
  28. {
  29. int c=getCount(b);
  30. while(c!=0)
  31. {
  32. a=a*10;
  33. c--;
  34. }
  35. a+=b;
  36. return a;
  37. }
  38.  
  39. int ex(int a,int in)
  40. {
  41. int p=getCount(a);
  42. if(p<in) return -1;
  43. int c=getNumber(a,in);
  44. a=c%10;
  45. return a;
  46. }
  47.  
  48. void spaces(char s,int n)
  49. {
  50. while(n!=0)
  51. {
  52. printf("%c",s);
  53. n--;
  54. }
  55. }
  56.  
  57. int main()
  58. {
  59. int a=0;
  60. int k=0;
  61.  
  62. scanf("%i",&a);
  63. scanf("%i",&k);
  64.  
  65. int res =a/k;
  66.  
  67. //printf("%i",getNumber(a,k));
  68. //printf("%i",soc(a,k));
  69. //printf("%i",ex(a,k));
  70. printf(" %i\t|%i\n",a,k);
  71. printf("-\t---\n");
  72. printf(" %i\t|%i\n",(k*ex(res,1)),res);
  73. printf(" ---\n");
  74.  
  75. int a1=getNumber(a,(getCount(k*ex(res,1))))-k*ex(res,1),
  76. b=0,
  77. a2=a1,
  78. in=2,
  79. nspace=1;
  80. char space=' ';
  81.  
  82. for(int i=getCount(k*ex(res,1));i<=getCount(a);i++)
  83. {
  84. if(a2==0)
  85. {
  86. nspace++;
  87. }
  88. a1=soc((a1-b),ex(a,i+1));
  89. spaces(space,nspace);
  90. printf(" %i\n",a1);
  91. spaces(space,nspace);
  92. printf("-\n");
  93. b=k*ex(res,in);
  94. in++;
  95. spaces(space,nspace);
  96. printf(" %i\n",b);
  97. spaces(space,nspace);
  98. printf(" ---\n");
  99. if(getCount(a1)>=getCount(a1-b)) nspace+=getCount(a1)-getCount(a1-b);
  100. a2=a1;
  101. if(ex(res,in)<0) break;
  102. }
  103. if((a1-b)==0) nspace--;
  104. spaces(space,nspace);
  105. printf(" %i\n",a1-b);
  106.  
  107. system("pause>0");
  108. return 0;
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement