fork download
  1. /**
  2.  * Author: Phan Duc Phuc
  3.  * Created: 18.04.2024 03:24:13
  4. **/
  5. #include <bits/stdc++.h>
  6. //#pragma GCC target("popcnt,lzcnt,bmi,bmi2,abm")
  7.  
  8. using namespace std;
  9.  
  10. void __print(int x) {cerr << x;}
  11. void __print(long x) {cerr << x;}
  12. void __print(long long x) {cerr << x;}
  13. void __print(unsigned x) {cerr << x;}
  14. void __print(unsigned long x) {cerr << x;}
  15. void __print(unsigned long long x) {cerr << x;}
  16. void __print(float x) {cerr << x;}
  17. void __print(double x) {cerr << x;}
  18. void __print(long double x) {cerr << x;}
  19. void __print(char x) {cerr << '\'' << x << '\'';}
  20. void __print(const char *x) {cerr << '\"' << x << '\"';}
  21. void __print(const string &x) {cerr << '\"' << x << '\"';}
  22. void __print(bool x) {cerr << (x ? "true" : "false");}
  23.  
  24. template<typename T, typename V>
  25. void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
  26. template<typename T>
  27. void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
  28. void _print() {cerr << "]\n";}
  29. template <typename T, typename... V>
  30. void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
  31. #ifndef ONLINE_OJUNGE
  32. #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
  33. #else
  34. #define debug(x...)
  35. #endif
  36.  
  37.  
  38. #define TIME (1.0 * clock()/ CLOCKS_PER_SEC)
  39. #define FOR(i,a,b) for(int i = (a);i <= (b);++i)
  40. #define FOD(i,b,a) for(int i = (b);i >= (a);--i)
  41. #define REP(i,a,b) for(int i = (a) ;i < (b);++i)
  42. #define file(NAME) if (fopen(NAME".inp","r")){ freopen(NAME".inp","r",stdin);freopen(NAME".out","w",stdout);}
  43.  
  44. string remove_leading_zeros(string num) {
  45. int i = 0;
  46. while (i < num.size() && num[i] == '0') {
  47. i++;
  48. }
  49. return (i == num.size()) ? "0" : num.substr(i);
  50. }
  51.  
  52. bool cmp(string &X,string &Y){
  53. if (X.size() != Y.size()) return (X.size() < Y.size());
  54. else{
  55. return (X < Y);
  56. }
  57. }
  58.  
  59. int main(){
  60. ios_base::sync_with_stdio(false);
  61. cin.tie(0);
  62. vector<string> v;
  63. int n;
  64. cin >> n;
  65. for(int i = 1; i <= n;i++){
  66. string s;
  67. cin >> s;
  68. string tmp = "";
  69. for(char x : s){
  70. if (x >= '0' && x <= '9'){
  71. tmp.push_back(x);
  72. }
  73. else{
  74. if (!tmp.empty()){
  75. string tmp2 = remove_leading_zeros(tmp);
  76. v.push_back(tmp2);
  77. tmp = "";
  78. }
  79. }
  80. }
  81. if (!tmp.empty()){
  82. string tmp2 = remove_leading_zeros(tmp);
  83. v.push_back(tmp2);
  84. }
  85. }
  86. sort(v.begin(),v.end(),cmp);
  87. for(auto x : v) cout << x << '\n';
  88. //cerr << "Time: " << TIME << "s\n";
  89. return (0 ^ 0);
  90. }
Success #stdin #stdout 0.01s 5300KB
stdin
4

01bond

02james007

03bond

04austinpowers000
stdout
0
1
2
3
4
7