Advertisement
JellyKuo

DS_Homework_1_1

Oct 14th, 2020
1,865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #pragma warning (disable:4996)
  3.  
  4. int main() {
  5.     int t, n;
  6.     scanf("%d", &n);
  7.     scanf("%d", &t);
  8.     t--;
  9.     int* values = new int[n];
  10.     int end = 0, ascendingCount = 0;
  11.     for (int i = 0; i < n; i++, end++) {
  12.         scanf("%d", &values[end]);
  13.         if (end > 0 && values[end - 1] < values[end]) {
  14.             ascendingCount++;
  15.             if (ascendingCount == t) {
  16.                 end -= t;
  17.                 ascendingCount = 0;
  18.                 for (int check = end - t + 1; check >= 0 && check < end; check++) {
  19.                     if (values[check - 1] < values[check]) {
  20.                         ascendingCount++;
  21.                     }
  22.                     else {
  23.                         ascendingCount = 0;
  24.                     }
  25.                 }
  26.                 end--;
  27.             }
  28.         }
  29.         else {
  30.             ascendingCount = 0;
  31.         }
  32.     }
  33.     for (int i = 0; i < end; i++) {
  34.         printf("%d ", values[i]);
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement