История изменений
Исправление beastie, (текущая версия) :
Такое сойдёт? (Quick'n'dirty решение)
#include <stdio.h>
char *strings[] = {
"abcd",
"qwerty",
"xyz",
"abcdef",
"whatever",
NULL,
};
int
common(char *a, char *b)
{
int n = 0;
while (*a++ == *b++)
n++;
return n;
}
int
main()
{
char **s, **p;
char *a = NULL, *b = NULL;
int n = 0;
for (s = strings; *s; s++) {
for (p = s+1; *p; p++) {
int c = common(*s, *p);
if (c > n) {
n = c;
a = *s;
b = *p;
}
}
}
if (a && b)
printf("most common: %s %s\n", a, b);
return 0;
}
most common: abcd abcdef
Исходная версия beastie, :
Такое сойдёт? (Quick'n'dirty решение)
#include <stdio.h>
char *strings[] = {
"abcd",
"qwerty",
"xyz",
"abcdef",
"whatever",
NULL,
};
int
common(char *a, char *b) {
int n = 0;
while (*a++ == *b++)
n++;
return n;
}
int
main()
{
char **s, **p;
char *a = NULL, *b = NULL;
int n = 0;
for (s = strings; *s; s++) {
for (p = s+1; *p; p++) {
int c = common(*s, *p);
if (c > n) {
n = c;
a = *s;
b = *p;
}
}
}
if (a && b)
printf("most common: %s %s\n", a, b);
return 0;
}
most common: abcd abcdef