由于数据量很小。。直接用最暴力的枚举了。。怎么简便怎么写
#include<stdio.h>
#include<string.h>
static int gcd(int a, int b)
{
if (!a)
return b;
return gcd(b % a, a);
}
int main()
{
char s[100], t[100];
while (scanf("%s", s), strcmp(s, "-1"))
{
scanf("%s", t);
int i, j, k, l, max = 0, com;
for (i = 0; s[i] != '\0'; i++)
for (j = 0; t[j] != '\0'; j++)
if (s[i] == t[j])
{
k = i + 1;
l = j + 1;
com = 1;
while (s[k] != '\0' && t[l] != '\0')
{
if (s[k] == t[l])
com++;
k++;
l++;
}
if (com > max)
max = com;
}
int a = max * 2;
int b = strlen(s) + strlen(t);
printf("appx(%s,%s) = ", s, t);
if (a == b)
puts("1");
else if (!a)
puts("0");
else
{
int g = gcd(a, b);
printf("%d/%d\n", a / g, b / g);
}
}
return 0;
}