fork download
  1. #include <iostream>
  2. #include <cmath>
  3. #include <list>
  4.  
  5. std::size_t CountDidit(int N){
  6. std::size_t i=0;
  7.  
  8. while (N != 0){
  9. i++;
  10. N /= 10;
  11. }
  12.  
  13. return i;
  14. }
  15.  
  16. int SnipeDigit(int N, int P){
  17. int A = std::pow(10, P);
  18. int B = N / A;
  19. int C = (N / (A * 10)) * 10;
  20.  
  21. return B - C;
  22. }
  23.  
  24. int Sign(int N){
  25. return N >= 0 ? 1:-1;
  26. }
  27.  
  28. int MakeHoge(int N){
  29. std::list<int> L;
  30.  
  31. int Count = CountDidit(N);
  32. int V = 0;
  33. int ret = 0;
  34. for (int i = 0; i < Count; i++){
  35. V = SnipeDigit(N, i);
  36. if (V != 0)L.push_front(V);
  37. }
  38. int S = L.size();
  39. for (int i = 0; i < Count - S; i++){
  40. L.push_back(0);
  41. }
  42.  
  43. for (auto i : L){
  44. ret = (ret * 10) + std::abs(i);
  45. }
  46. return ret*Sign(N);
  47. }
  48.  
  49. int main(){
  50. int V = 123456789;
  51. int V2 = 1020304050;
  52.  
  53. int p = V2;
  54.  
  55. int N = MakeHoge(p);
  56.  
  57. std::cout << p << "=" << N << std::endl;
  58.  
  59. return 0;
  60. }
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
1020304050=1234500000