| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
我用的是数组,检查几遍没问题,感觉很正确,但是wa~求解惑####//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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator