Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 20
- int comp (const void* str1, const void* str2) {
- return (strcmp(*(char**)str1, *(char**)str2));
- }
- int count (char* text) {
- int mem = N, i = 1, len, counter = 1, max = 1;
- char** array = (char**)malloc(mem*sizeof(char*));
- array[0] = strtok(text," ");
- while (array[i-1] != NULL) {
- array[i] = strtok(NULL," ");
- i++;
- if (mem == i) {
- mem += mem;
- realloc(array, mem*sizeof(char*));
- }
- }
- len = i-1;
- // for ( i=0; i < len; i++) {
- // printf("%s\n", array[i]);
- // }
- i = 0;
- if (!len) {
- return 0;
- }
- qsort(array, len, sizeof(char*), comp);
- while ( i < len-1 ){
- i++;
- if ( !strcmp(array[i], array[i-1]) ) {
- counter++;
- }
- //printf("%d", len);
- if ( strcmp(array[i], array[i-1]) || i == len - 1) {
- if (max < counter) {
- max = counter;
- counter = 1;
- }
- }
- }
- return max;
- }
- int main() {
- int n = 0;
- char* text = (char*) malloc (201*sizeof(char));
- fgets(text, 201, stdin);
- n = count(text);
- printf("%d", n);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement