Created
December 31, 2017 14:44
-
-
Save ashok-arora/4c68c2e44d17175ac88fa10dda540a53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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