Advertisement
quetzelcoatlus

6.c

Dec 6th, 2022 (edited)
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.71 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int uniques(const char* str){
  6.     char count[256] = {0};
  7.     int c = 0;
  8.     for(unsigned int i=0; i<strlen(str); i++){
  9.         count[(int)str[i]]=1;
  10.     }
  11.     for(int i=0; i<256; i++)
  12.         c += count[i];
  13.  
  14.     return c;
  15. }
  16.  
  17. void main(){
  18.     char *line = NULL;
  19.     size_t len = 0;
  20.     ssize_t nread;
  21.  
  22.  
  23.     while ((nread = getline(&line, &len, stdin)) != -1) {
  24.         char *l=line;
  25.         char tmp[5];
  26.         while(*(l+3)){
  27.             strncpy(tmp,l,4);
  28.             if(uniques(tmp) == 4){
  29.                 printf("%s - %ld\n",tmp, l-line+4);
  30.                 break;
  31.             }
  32.             l++;
  33.         }
  34.     }
  35.     free(line);
  36. }
Tags: adventofcode
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement