#include <iostream>
#include <sstream>
#include <string>
#include <chrono>
int ForwardIndex(std::string& str, int P){
std::size_t i=0;
for (i = P; i < str.size(); i++){
if (str[i] == '0') break;
}
return i;
}
int MakeHoge(int N){
std::stringstream ss;
std::string str;
int V = 0;
ss << N;
ss >> str;
std::size_t Idx = ForwardIndex(str, 0);
for (std::size_t i = Idx+1; i < str.size(); i++){
if (str[i] != '0'){
std::swap(str[i], str[Idx]);
Idx = ForwardIndex(str, Idx);
if (i <= Idx) i = Idx;
}
}
ss.clear();
ss << str;
ss >> V;
return V;
}
int main(){
int v = 123456789;
int v2 = 1020304050;
int v3 = 20010307;
int p = v3;
auto S = std::chrono::system_clock::now();
int N = 0;
for (int i = 0; i < 100000; i++){
N = MakeHoge(p);
}
auto E = std::chrono::system_clock::now();
auto El = std::chrono::duration_cast<std::chrono::milliseconds>(E - S);
std::cout << p << "=" << N << ' ' << "Ellipsed=" << El.count() << "msec" << std::endl;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3N0cmVhbT4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPGNocm9ubz4KCmludCBGb3J3YXJkSW5kZXgoc3RkOjpzdHJpbmcmIHN0ciwgaW50IFApewoJc3RkOjpzaXplX3QgaT0wOwoJZm9yIChpID0gUDsgaSA8IHN0ci5zaXplKCk7IGkrKyl7CgkJaWYgKHN0cltpXSA9PSAnMCcpIGJyZWFrOwoJfQoJcmV0dXJuIGk7Cn0KCmludCBNYWtlSG9nZShpbnQgTil7CglzdGQ6OnN0cmluZ3N0cmVhbSBzczsKCXN0ZDo6c3RyaW5nIHN0cjsKCWludCBWID0gMDsKCglzcyA8PCBOOwoJc3MgPj4gc3RyOwoKCXN0ZDo6c2l6ZV90IElkeCA9IEZvcndhcmRJbmRleChzdHIsIDApOwoKCWZvciAoc3RkOjpzaXplX3QgaSA9IElkeCsxOyBpIDwgc3RyLnNpemUoKTsgaSsrKXsKCQlpZiAoc3RyW2ld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