⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pku1318.cpp

📁 这是ACM 方面的资料 是PKU的 北京大学的出来的
💻 CPP
字号:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct
{
	char s0[15];
	int sl;
	char s1[15];
} Word;

Word dic[100];

void strsort(char *s, int l)
{
	int i, j;
	char ch;
	for (i = 0; i < l - 1; i++)
	{
		for (j = i + 1; j < l; j++)
		{
			if (s[i] < s[j])
			{
				ch = s[i];
				s[i] = s[j];
				s[j] = ch;
			}
		}
	}
}

int cmp(const void *a, const void *b)
{
	Word *c = (Word *)a;
	Word *d = (Word *)b;
	return strcmp(c->s0, d->s0);
}

int main()
{
	int i, l, n, p;
	char s[15];
	i = 0;
	while (scanf("%s", s) != -1)
	{
		if (strcmp(s, "XXXXXX") == 0)
		{
			break;
		}
		
		strcpy(dic[i].s0, s);
		strcpy(dic[i].s1, s);
		dic[i].sl = strlen(s);
		
		strsort (dic[i].s1, dic[i].sl);

		i++;
	}
	n = i;
	qsort(dic, n, sizeof(dic[0]), cmp);

	while (scanf("%s", s) != -1)
	{
		if (strcmp(s, "XXXXXX") == 0)
		{
			break;
		}

		l = strlen(s);
		strsort(s, l);
		for (i = 0, p = 0; i < n; i++)
		{
			if (l == dic[i].sl && strcmp(dic[i].s1, s) == 0)
			{
				printf("%s\n", dic[i].s0);
				p++;
			}
		}
		if (p == 0)
		{
			printf("NOT A VALID WORD\n");
		}
		printf("******\n");
	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -