您的位置:首页 > 其它

ZOJ-1170

2014-07-03 22:52 162 查看
由于数据量很小。。直接用最暴力的枚举了。。怎么简便怎么写

#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: