猜单词

//显然我想复杂了,但是在这里我自己第一次尝试了下结构体+数组,双重循环如何从内层直接退出的写法,我觉得很有意思.


#include <stdio.h>
#include <string.h>

typedef struct
{
	char strchar;
	int valuestr;
} strstruct;

strstruct chuan[28];

int shifouzhishu(int i)
{
	int j = 2;
	for (; j <= i; j++)
	{
		if (i % j == 0)
			break;
	}
	if (j != i)
		return 0; 
	else
		return 1;
}

int main()
{
	char maxc;
	int maxs;
	char minc;
	int mins;
	char str[101];
	gets(str);
	int ii = 0;
	int a = 0;
	for (int i = 0; i < strlen(str); i++)
	{
		for (int j = 0; j <= 100; j++)
		{
			if (chuan[j].strchar == str[i])
			{
				chuan[j].valuestr++;
				a = 1;
			}
		}
		if (a == 1)
		{
			a = 0;
			continue;
		}
		else
			a = 0;
		chuan[ii].strchar = str[i];
		chuan[ii].valuestr = 1;
		ii++;
	}
	maxc = chuan[0].strchar;
	minc = chuan[0].strchar;
	mins = chuan[0].valuestr;
	maxs = chuan[0].valuestr;
	for (int i = 1; i < ii; i++)
	{
		if (maxs < chuan[i].valuestr)
		{
			maxs = chuan[i].valuestr;
			maxc = chuan[i].strchar;
		}
		if (mins > chuan[i].valuestr)
		{
			mins = chuan[i].valuestr;
			minc = chuan[i].strchar;
		}
	}
	a = (int)(maxs - mins);
	if (shifouzhishu(a))
	{
		printf("Lucky Word\n");
		printf("%d", a);
	}
	else
	{
		printf("No Answer\n");
		printf("%d", a);
	}
	return 0;
}