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