Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- void solve(char * s, long long n) {
- char * p1 = NULL, * p2 = s + n;
- if (n == 1) {
- p1 = s;
- }
- for (long long i = n - 1; i >= 1; --i) {
- if (s[i - 1] < s[i]) {
- p1 = s + i - 1;
- } else {
- if (p1 != NULL) {
- break;
- }
- p2 = s + i;
- }
- }
- if (p1 != NULL) {
- long long i = 0;
- while (p1 + i != p2) {
- printf("%c", *(p1 + i));
- i++;
- }
- }
- }
- int main(void) {
- long long n = 0;
- scanf("%lld", &n);
- char * s = (char *)malloc((n + 1) * sizeof(char));
- getchar();
- for (int i = 0; i < n; ++i) {
- scanf("%c", s + i);
- }
- solve(s, n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement