Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我用的是数组,检查几遍没问题,感觉很正确,但是wa~求解惑####

Posted by dyz007 at 2013-08-14 21:23:45 on Problem 1789
//1003
#include <stdio.h>
#include <string.h>
#define M 2010
char s[M][8];
int shu[M];

int cha(char s1[], char s2[], int n)
{
	int i, j = 0;
	for(i = 0; i < n; i++){

			if(s1[i] != s2[i])
				j++;

	}
	return j;
}

int main()
{
	int n, len, sum, min, t, i, j;
	while(scanf("%d%*c", &n) && n){

		sum = 0;
		memset(s, 0, M);
		for(i = 1; i <= n; i++){

				scanf("%s", s[i]);

		}
		len = strlen(s[1]);
		for(i = 2; i <= n; i++){

			memset(shu, 0, M);
			for(j = 1; j <= i - 1; j++){

					shu[j] = cha(s[j], s[i], len);//计算差值
					
			}
			t = j - 1;//t是要比较的数据个数
			if(t == 1)
			{
				sum += shu[1];
				continue;
			}
			min = M;//min是差值的最小值,在这对min初始化,因为每次求min之前都要赋初值
			for(j = 1; j <= t; j++){

					if(min > shu[j])
						min = shu[j];

			}
			sum += min;
		}
		printf("The highest possible quality is 1/%d.\n", sum);
		
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator