[ create a new paste ] login | about

Link: http://codepad.org/DLOmHNTe    [ raw code | output | fork ]

C++, pasted on Mar 26:
#include <stdio.h>
#include <string.h>

int main(int argc, char* argv[])
{
	static char str[256] = "apple,fruit,orange,help,work.\0";

	printf("%s\n",str);

	char ch = '\0'; int max_count = 0;
	for (int i = 0; str[i] != '\0'; i++)
	{
		int count = 0;
		char* wd = strtok(str, ",");
		while (wd != NULL)
		{
			if (strchr(wd, str[i]) != NULL)
				count++;

			wd = strtok(NULL, ",");
		}

	    if (count > max_count || max_count == 0)
		 { max_count = count; ch = str[i]; }
	}

	printf("%c --> %d\n",ch,max_count);

	return 0;
}


Output:
1
2
apple,fruit,orange,help,work.
a --> 2


Create a new paste based on this one


Comments: