fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <chrono>
  5.  
  6. int ForwardIndex(std::string& str, int P){
  7. std::size_t i=0;
  8. for (i = P; i < str.size(); i++){
  9. if (str[i] == '0') break;
  10. }
  11. return i;
  12. }
  13.  
  14. int MakeHoge(int N){
  15. std::stringstream ss;
  16. std::string str;
  17. int V = 0;
  18.  
  19. ss << N;
  20. ss >> str;
  21.  
  22. std::size_t Idx = ForwardIndex(str, 0);
  23.  
  24. for (std::size_t i = Idx+1; i < str.size(); i++){
  25. if (str[i] != '0'){
  26. std::swap(str[i], str[Idx]);
  27. Idx = ForwardIndex(str, Idx);
  28. if (i <= Idx) i = Idx;
  29. }
  30. }
  31.  
  32. ss.clear();
  33. ss << str;
  34. ss >> V;
  35.  
  36. return V;
  37. }
  38.  
  39. int main(){
  40.  
  41. int v = 123456789;
  42. int v2 = 1020304050;
  43. int v3 = 20010307;
  44. int p = v3;
  45.  
  46. auto S = std::chrono::system_clock::now();
  47. int N = 0;
  48. for (int i = 0; i < 100000; i++){
  49. N = MakeHoge(p);
  50. }
  51.  
  52. auto E = std::chrono::system_clock::now();
  53.  
  54. auto El = std::chrono::duration_cast<std::chrono::milliseconds>(E - S);
  55. std::cout << p << "=" << N << ' ' << "Ellipsed=" << El.count() << "msec" << std::endl;
  56.  
  57. return 0;
  58. }
Success #stdin #stdout 0.26s 3432KB
stdin
Standard input is empty
stdout
20010307=21370000 Ellipsed=263msec