View Code of Problem 126

#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>
#include<string.h>
#include<math.h>
int main()
{
	 struct MyStruct
	{
		char st[50];
		int n;
	}str[100];
	
	int n, m,i,j,s;
	
	while (scanf("%d%d", &n, &m) != EOF)
	{
		for(s=0;s<m;s++)
		{
			scanf("%s", str[s].st);
			str[s].n = 0;
			for (i = 0; i < n; i++)
			{
				for (j = i; j < n; j++)
				{
					if (str[s].st[i]>str[s].st[j])
					{
						str[s].n++;
					}
				}
			}
		}
		int max = 0;
		for (i = 0; i < n; i++)
		{
			if (str[max].n< str[i].n)
				max = i;
		}
		max = str[max].n + 10;
		for (i = 0; i < m; i++)
		{
			int min = 0;
			for (j = 0; j < m; j++)
			{
				if (str[min].n > str[j].n)
					min = j;
			}
			printf("%s\n", str[min].st);
			str[min].n = max;
		}
		
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 126