Advertisement
_takumi

idz2

Oct 31st, 2022 (edited)
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. int main(void) {
  5.     long long n = 0;
  6.     scanf("%lld", &n);
  7.     char * s = (char *)malloc((n + 1) * sizeof(char));
  8.     char * p1 = NULL, * p2 = s + n;
  9.     getchar();
  10.     for (int i = 0; i < n; ++i) {
  11.         scanf("%c", s + i);
  12.     }
  13.     for (int i = n - 1; i >= 1; --i) {
  14.         if (s[i - 1] < s[i]) {
  15.             p1 = s + i - 1;
  16.         } else {
  17.             if (p1 != NULL) {
  18.                 break;
  19.             }
  20.             p2 = s + i;
  21.         }
  22.     }
  23.     if (p1 != NULL) {
  24.         int i = 0;
  25.         while (p1 + i != p2) {
  26.             printf("%c", *(p1 + i));
  27.             i++;
  28.         }
  29.     }
  30.     return 0;
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement