nitroprusside

Untitled

Jun 23rd, 2025
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main() {
  5.     char str[10000] = "", line[1000];
  6.  
  7.     // Read input until a blank line
  8.     while (fgets(line, sizeof(line), stdin)) {
  9.         if (strcmp(line, "\n") == 0) break;
  10.         strcat(str, line);
  11.     }
  12.  
  13.     // Remove all newline characters
  14.     for (char *p = str; *p; p++) {
  15.         if (*p == '\n') *p = ' ';
  16.     }
  17.  
  18.     char *start = str, *stop = str;
  19.     int maxLen = 0;
  20.  
  21.     for (char *i = str; *i; i++) {
  22.         int seen[256] = {0};
  23.         int len = 0;
  24.         char *j = i;
  25.  
  26.         while (*j) {
  27.             if (*j != ' ' && seen[(unsigned char)*j]) break;
  28.             if (*j != ' ') {
  29.                 seen[(unsigned char)*j] = 1;
  30.                 len++;
  31.             }
  32.             j++;
  33.         }
  34.  
  35.         if (len >= maxLen) {
  36.             maxLen = len;
  37.             start = i;
  38.             stop = j;
  39.         }
  40.     }
  41.  
  42.     // Print result in one line
  43.     for (char *p = start; p < stop; p++) {
  44.         putchar(*p);
  45.     }
  46.  
  47.     return 0;
  48. }
  49.  
Advertisement
Add Comment
Please, Sign In to add comment