fork download
  1. #include <algorithm>
  2. #include <vector>
  3. #include <iostream>
  4. using namespace std;
  5. class BigInt;
  6. vector<BigInt*> World;
  7. void WorldEnd()
  8. {
  9. int Z=World.size();
  10. for (int i=0; i<Z; i++)
  11. {
  12. delete World[i];
  13. }
  14. World.clear();
  15. }
  16. class BigInt
  17. {
  18. public:
  19. vector<int> Me;
  20. BigInt(int inn);
  21. BigInt(vector<int> inn);
  22. BigInt* reverse();
  23. BigInt* add(BigInt* that);
  24. void print();
  25. bool isLoop();
  26. //~BigInt();
  27. };
  28. bool BigInt::isLoop()
  29. {
  30. if (Me.size()==1)
  31. return true;
  32. else if (Me.size()>=2)
  33. {
  34. if (Me.size()%2==0)
  35. {
  36. for (int i=0; i<= Me.size()/2 ; i++)
  37. {
  38. if (Me[i]!= Me[ Me.size()-1-i])
  39. return false;
  40. }
  41. return true;
  42. }else
  43. {
  44. for (int i=0; i<=(Me.size()-1)/2; i++)
  45. {
  46. if (Me[i]!= Me[ Me.size()-1-i])
  47. return false;
  48. }
  49. return true;
  50. }
  51. }
  52. return false;
  53. }
  54. BigInt* BigInt::add(BigInt* that)
  55. {
  56. vector<int> dest;
  57. int carry=0;
  58. for(int i=0; i<that->Me.size(); i++)
  59. {
  60. int sum= Me[i] + that->Me[i]+carry;
  61. if (sum>=10)
  62. {
  63. carry=1; dest.push_back( sum-10);
  64. }else {
  65. carry=0; dest.push_back( sum);
  66. }
  67. }
  68. if (carry==1)
  69. dest.push_back(1);
  70. BigInt* ret=new BigInt(dest);
  71. World.push_back(ret);
  72. return ret;
  73. }
  74. BigInt* BigInt::reverse()
  75. {
  76. vector<int> hand;
  77. for (int i=Me.size()-1; i>=0; i--)
  78. hand.push_back(Me[i]);
  79. BigInt* ret= new BigInt(hand);
  80. World.push_back(ret);
  81. return ret;
  82. }
  83. BigInt::BigInt(int inn)
  84. {
  85. while(inn>=10)
  86. {
  87. Me.push_back(inn%10);
  88. inn /=10;
  89. }
  90. Me.push_back(inn);
  91. }
  92. BigInt::BigInt(vector<int> inn)
  93. {
  94. for (int i=0; i<inn.size(); i++)
  95. {
  96. Me.push_back(inn[i]);
  97. }
  98.  
  99. }
  100. void BigInt::print()
  101. {
  102. for (int i=Me.size()-1; i>=0; i--)
  103. {
  104. cout<< Me[i];
  105. }
  106. }
  107.  
  108. void ACM10018(int P)
  109. {
  110.  
  111. BigInt* P1=new BigInt(P);
  112. BigInt* P2;
  113. BigInt* P3;
  114. World.push_back(P1);
  115. int Step=0;
  116. do
  117. { P2=P1->reverse();
  118. P3=P1->add(P2);
  119. Step+=1;
  120. if (!P3->isLoop())
  121. P1=P3;
  122. else
  123. break;
  124. }while(true);
  125. cout<< Step<<" ";
  126. P3->print();
  127. cout<<endl;
  128. }
  129. int main()
  130. {
  131.  
  132. int P,N;
  133. cin>>N;
  134. if (N>0 && N<=100)
  135. {
  136. for (int i=0; i<N; i++)
  137. {
  138. cin>>P;
  139. ACM10018(P);
  140. WorldEnd();
  141. }
  142. }
  143.  
  144. return 0;
  145. }
  146.  
Success #stdin #stdout 0.01s 2684KB
stdin
Standard input is empty
stdout
Standard output is empty