Advertisement
uzimane_

монотонная и строго монотонная последовательность

Jul 10th, 2020
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. freopen("input.txt", "r", stdin);
  8. freopen("output.txt", "w", stdout);
  9.  
  10. int n;
  11. cin >> n;
  12. int a, b;
  13. int k = 0;
  14. cin >> a >> b;
  15. int j = 1;
  16.  
  17. if (a == b)
  18. {
  19. while ((a == b) && (j < n))
  20. {
  21. a = b;
  22. cin >> b;
  23. k = 6;
  24. j++;
  25. }
  26. }
  27.  
  28. if (a > b)
  29. {
  30. for (int i = 1; i < n; i++)
  31. {
  32. if ((a > b) && ((k == 1) || (k == 0) || (k == 6)))
  33. {
  34. a = b;
  35. cin >> b;
  36. k = 1;
  37. continue;
  38. }
  39.  
  40. if ((a >= b) && ((k == 1) || (k == 2) || (k == 0)))
  41. {
  42. a = b;
  43. cin >> b;
  44. k = 2;
  45. continue;
  46. }
  47.  
  48. if (a < b)
  49. {
  50. k = 5;
  51. break;
  52. }
  53. }
  54. }
  55.  
  56. if (a < b)
  57. {
  58. for (int i = 1; i < n; i++)
  59. {
  60. if ((a < b) && ((k == 3) || (k == 0) || (k == 6)))
  61. {
  62. a = b;
  63. cin >> b;
  64. k = 3;
  65. continue;
  66. }
  67.  
  68. if ((a <= b) && ((k == 0) || (k == 3) || (k == 4)))
  69. {
  70. a = b;
  71. cin >> b;
  72. k = 4;
  73. continue;
  74. }
  75.  
  76. if (a > b)
  77. {
  78. k = 5;
  79. break;
  80. }
  81. }
  82. }
  83.  
  84.  
  85.  
  86. if ((k == 1) || (k == 3))
  87. {
  88. cout << "2";
  89. }
  90. if ((k == 2) || (k == 4))
  91. {
  92. cout << "1";
  93. }
  94. if ((k == 5) || (k == 6))
  95. {
  96. cout << "0";
  97. }
  98.  
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement