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, FILE *output) {
- 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) {
- fprintf(output, "%c", *(p1 + i));
- i++;
- }
- }
- }
- int main(int argc, char **argv) {
- FILE *input, *output;
- input = fopen(argv[1], "r");
- output = fopen(argv[2], "w");
- long long n = 0;
- fscanf(input, "%lld", &n);
- char * s = (char *)malloc((n + 1) * sizeof(char));
- fgetc(input);
- fgets(s, n + 1, input);
- solve(s, n, output);
- fclose(input);
- fclose(output);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement