fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define sd(x) scanf("%d", &x)
  4. #define slld(x) scanf("%lld", &x)
  5. #define all(x) x.begin(), x.end()
  6. #define For(i, st, en) for(ll i=st; i<en; i++)
  7. #define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
  8. #define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
  9. #define pb push_back
  10. #define ll long long
  11. #define int long long
  12. #define mp make_pair
  13. #define F first
  14. #define S second
  15. typedef pair<int, int> pii;
  16. #define MOD 1000000007
  17. #define INF 1000000000000000007
  18. #define MAXN 300005
  19.  
  20. // it's swapnil07 ;)
  21.  
  22. signed main(){
  23. fast
  24. #ifdef SWAPNIL07
  25. freopen("input.txt","r",stdin);
  26. freopen("output.txt","w",stdout);
  27. #endif
  28. string s; cin>>s;
  29. int n = s.length();
  30. bool flag = false;
  31. set<int> ones;
  32. For(i, 0, n){
  33. if(s[i]=='1'){
  34. ones.insert(i);
  35. }
  36. else{
  37. if(ones.size()){
  38. ones.erase(*ones.rbegin());
  39. }
  40. }
  41. }
  42.  
  43. For(i, 0, n){
  44. if(ones.find(i)!=ones.end()){
  45. cout<<0;
  46. }
  47. else{
  48. cout<<s[i];
  49. }
  50. }
  51. return 0;
  52. }
Success #stdin #stdout 0s 4500KB
stdin
Standard input is empty
stdout
Standard output is empty