Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.7 kB
1
Indexable
Never
#include <stdio.h>
#include <string.h>

char *find_min_substring(char *sequence) {
    int length = strlen(sequence);
    char *min_substring = sequence; // Initialize min_substring to the beginning of sequence
    
    for (int i = 1; i < length - 3; i++) {
        if (strncmp(sequence + i, min_substring, 4) < 0) {
            min_substring = sequence + i;
        }
    }
    
    return min_substring;
}

int main() {
    char *sequence = "oBrbXUUzQRlI4cpzmFa1ncm9atD3VFh43cEJ8uv4DJYLhDrdux45dCFzPXaLzyVlafhbqh3xiiROuKsyG33Muk2QGmCGzSpwNCEHjss3vjV22Jn1nkb1qMOL6ggWzE8F4XG2ORaUUwzt0B1mVwnZoNzI2i4VY1iRWLkXQyqp2myEJHUW4L0zgAnPFkSV2pv971lTtXuw5fxzaZ1E5JfcH5wOdu238qxrvTuH9V0JQwtxNDMzDM8dxWMWRQEp1aUJT1aIY8VVAaFeDonx1TuOMbTV1E6WRMpTIclQGMrtnBpYamvJPlrvJB2ilKwbX1TXG8rWut1pjZmWLdnqktWy1ZqCWwpQ0J4cNKO9TfRsr0CkmEPtRAXCsSn5yiMMXacFru2ihXaJyRoZahqFw5MRR3eRA07MrXTfCFEkh7bwG5n4J51R3IjB2uIoO5wib7pCm5FFYhky2cEiVnaxFIo4IrbwV0GhR2nJMrD4aWiNkYI0gIJjv8ZQRAVKg9aFpxJjJo9Q7yONElZvQJ16yS5zWU5DImdX5ndURGCvtvE5HRT0fifX8jU1x0kw2oL9QxJ6tmO0F1Lkqkt0FcZukh5KElPMEABRHUcZSgkVnuwq3yVlaPqIZ3a1Ma7uH34H4dYZv2dnYMN2r6RnGBrQhRZrSrdBQB9EMlVUCztKK4m96zdNfZhdHuzT4rWTz4qDbODfAfnlQwEzZnWVQQVE6yIVxdVNeBRzKw6C1DK0FtvCO6Y8Zkb8V0e8LQXCIVcAU3nqY2oHkgPIkRYOT04axTPL6FQrt0aIYYrZzBhylPd4SjmOSN9QHzYuzKwKVYtL84lt53qS7MitLBR443kjHdT5H9jeuziuyDr2E2fGf472qu4TTSRONYJWmuu9p5t3qMU7xKgMbWN0rt4nrk2sZr8T1DTsSxkiz0O29Y0Jv5PzzjCWadsvRZOjTflD8BRsOMslsvULObuBxyI9nRbhIo7bM5j6p3PxvkGvwhDw4qLTMa5RxMyydp51flAPKA0Lqv5Q";
    
    char *min_substring = find_min_substring(sequence);
    printf("The 4-character substring with the lowest lexicographic value is: %.4s\n", min_substring);
    
    return 0;
}
Leave a Comment