Skip to content

Instantly share code, notes, and snippets.

@ashok-arora
Created December 31, 2017 14:44
Show Gist options
  • Save ashok-arora/4c68c2e44d17175ac88fa10dda540a53 to your computer and use it in GitHub Desktop.
Save ashok-arora/4c68c2e44d17175ac88fa10dda540a53 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
int good = 0;
FILE *fp = fopen("input.txt","r");
char str[4092];
while (fgets(str, sizeof str, fp) != NULL){
const char brk[] = " \n";
/* strtok breaks when either " " or "\n" is encountered hence they can
* be clubbed together.
* fgets() reads the string + \n, which is why breakpoint is " " and
* "\n", otherwise it will read the not needed \n.
*/
char *token;
int count = 0;
int flag = 0;
char *list[30];
token = strtok(str,brk);
list[0] = token;
for ( int i = 1 ; token != NULL ; i++){
token = strtok(NULL, brk);
++count;
list[i] = token;
}
for( int i = 0 ; i < count ; i++ ){
for ( int k = i+1 ; k < count ; k++){
if ( strcmp(list[k],list[i]) == 0 )
++flag;
}
}
if (flag == 0 )good++;
}
fclose(fp);
printf("%d",good);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment