Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <stdlib.h>
  4. using namespace std;
  5.  
  6. int main()
  7. {ifstream in("robot3.in");
  8. ofstream out("robot3.out");
  9. char c;
  10. int a=0,b=0,n=0,m=0,z=0,e,d,p;
  11. in>>p;
  12.  
  13. if(p==1){
  14. while(!in.eof()){
  15. in>>c;
  16. if (c=='A')a++;
  17. }
  18. out<<a<<endl;
  19. }
  20.  
  21. if(p==2){
  22. in>>c;
  23. b=0;
  24. while(c!='T'){
  25. if (c=='D'){
  26. in>>c;
  27. a=c-48;
  28. b=(b+a)%10;
  29. }else if (c=='S'){
  30. in>>c;
  31. a=c-48;
  32. b=(b+10-a)%10;
  33. }
  34. if(c=='A')out<<b;
  35. in>>c;
  36. }
  37. }
  38.  
  39. if(p==3){
  40. in>>a;
  41. if(a==0)out<<"A";
  42. else
  43. if(a<10){if(10-a<a)out<<'S'<<10-a<<'A';
  44. else out<<'D'<<a<<'A';
  45. }
  46. else
  47. {
  48. z=0;
  49. while(a%10==0){
  50. z++;
  51. a=a/10;
  52. }
  53. while(a!=0){
  54. b=b*10+a%10;
  55. a=a/10;
  56. }
  57. a=b;
  58. b=a%10;
  59. if(10-b<b)out<<'S'<<10-b<<'A';
  60. else out<<'D'<<b<<'A';
  61. a=a/10;
  62. while(a!=0){
  63. if(b==a%10)out<<'A';
  64. else
  65. if(b>a%10)
  66. if(10-b+a%10<=b-a%10)out<<'D'<<10-b+a%10<<'A';
  67. else out<<'S'<<b-a%10<<'A';
  68. else if(10-a%10+b<a%10-b)out<<'S'<<10-a%10+b<<'A';
  69. else out<<'D'<<a%10-b<<'A';
  70. b=a%10;
  71. a=a/10;
  72. }
  73. if(z!=0){
  74. if(10-b<b)out<<'D'<<b;
  75. else out<<'S'<<b;
  76. while(z!=0){
  77. out<<'A';
  78. z--;
  79. }
  80. }
  81. }
  82. out<<'T';
  83. }
  84. in.close();
  85. out.close();
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement