Guest User

Untitled

a guest
Mar 15th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define long long long int
  4. using namespace std;
  5.  
  6. // @author: pashka
  7.  
  8. int main() {
  9. ios::sync_with_stdio(false);
  10.  
  11. vector<string> a;
  12. string s;
  13. while (cin >> s) {
  14. // if (s == ".")
  15. // break;
  16. a.push_back(s);
  17. }
  18.  
  19. sort(a.begin(), a.end(), [](string &a, string &b) -> bool {
  20. int i = 0;
  21. int j = 0;
  22. bool first = true;
  23. int za = 0;
  24. int zb = 0;
  25. while (i < a.size() && j < b.size()) {
  26. if (isdigit(a[i])) {
  27. if (isdigit(b[j])) {
  28. while (a[i] == '0') {
  29. if (first) za++;
  30. i++;
  31. }
  32. int li = i;
  33. while (isdigit(a[i])) {
  34. i++;
  35. }
  36. int ri = i;
  37. while (b[j] == '0') {
  38. if (first) zb++;
  39. j++;
  40. }
  41. int lj = j;
  42. while (isdigit(b[j])) {
  43. j++;
  44. }
  45. int rj = j;
  46. if (ri - li != rj - lj) {
  47. return ri - li < rj - lj;
  48. }
  49. for (int t = 0; t < ri - li; t++) {
  50. if (a[li + t] != b[lj + t]) {
  51. return a[li + t] < b[lj + t];
  52. }
  53. }
  54. if (za != zb) first = false;
  55. } else {
  56. return true;
  57. }
  58. } else {
  59. if (isdigit(b[j])) {
  60. return false;
  61. } else {
  62. if (a[i] < b[j]) return true;
  63. if (a[i] > b[j]) return false;
  64. i++;
  65. j++;
  66. }
  67. }
  68. }
  69. if (i == a.size() && j == b.size()) {
  70. if (first)
  71. return a < b;
  72. else
  73. return za > zb;
  74. }
  75. return i == a.size() && j < b.size();
  76. });
  77.  
  78. for (string x : a) {
  79. cout << x << "\n";
  80. }
  81.  
  82. return 0;
  83. }
  84. //293566DZ
Advertisement
Add Comment
Please, Sign In to add comment