Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int n, m, w = 0;
  10. cin >> n >> m;
  11. vector <string> a(n);
  12. for(int i = 0; i < n; i++) cin >> a[i];
  13. for(;;)
  14. {
  15. bool x = 1;
  16. for(int i = 0; i < n - 1; i++)
  17. {
  18. x = x and (a[i] <= a[i + 1]);
  19. }
  20. if(x) break;
  21. else
  22. {
  23. int b = 0;
  24. bool t = 0;
  25. for(unsigned int i = 0; i < a.size(); i++)
  26. {
  27. for(int j = 0; j < n - 1; j++)
  28. {
  29. if(a[j].substr(i, a.size()) > a[j + 1].substr(i, a.size()))
  30. {
  31. b = (int) i;
  32. cout << b << endl;
  33. w++;
  34. t = 1;
  35. break;
  36. }
  37. }
  38. if(t) break;
  39. }
  40. for(int i = 0; i < n; i++)
  41. {
  42. a[i] = a[i].substr(0, b) + a[i].substr(b + 1, a.size());
  43. }
  44. }
  45. }
  46. cout << w;
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement