View Code of Problem 97

#include<stdio.h>
#include<string.h>
void main()
{
	int n;
	while (scanf("%d",&n)!=EOF)
	{
		if (n == 0)break;
		char a[1000][50],b[1000][50];
		char s[50];
		int k = 0;
		for (int i = 0; i < n; i++)
		{
			scanf("%s", a[i]);
		}
		for (int i = 0; i < n; i++)
		{
			int len = strlen(a[i]);
			if (a[i][len - 1] == 'e'&&a[i][len - 2] == 'x'&&a[i][len - 3] == 'e')
			{
				strcpy(s, a[i]);
				s[len - 4] = '\0';
				for (int j = 0; j < n; j++)
				{
					if (strcmp(s, a[j]) == 0 && i != j)
					{
						strcpy(b[k++], a[i]);
						break;
					}
				}
			}
		}
		if (k > 0)
		{
			if (k == 1) printf("%s\n", b[0]);
			else
			{
				char t[1000];
				for (int i = 0; i < k; i++)
				{
					for (int j = i; j < k - 1; j++)
					{
						if (strcmp(b[j], b[j + 1]) > 0)
						{
							strcpy(t, b[j]);
							strcpy(b[j], b[j + 1]);
							strcpy(b[j + 1], t);
						}
					}
				}
				for (int i = 0; i < k; i++)
				{
					puts(b[i]);
				}
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 97