栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 1580 String Matching

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 1580 String Matching

#include <iostream>#include <cstdlib>#include <cstdio>#include <cstring>using namespace std;#define maxn 105char st1[maxn], st2[maxn];int len;int gcd(int a, int b){    if (a == 0)        return 1;    b %= a;    while (b)    {        a %= b;        swap(a, b);    }    return a;}int cal(char *st1, char *st2){    int ret = 0;    for (int i = 0; st1[i] && st2[i]; i++)        if (st1[i] == st2[i]) ret++;    return ret;}int work(){    int len1 = strlen(st1);    int len2 = strlen(st2);    int ret = cal(st1, st2);    len = len1 + len2;    for (int i = 1; i < len1; i++)        ret = max(ret, cal(st1 + i, st2));    for (int i = 1; i < len2; i++)        ret = max(ret, cal(st1, st2 + i));    return ret;    }int main(){    while (scanf("%s", st1), strcmp(st1, "-1"))    {        scanf("%s", st2);        int ans = work() * 2;        int g = gcd(ans, len);        ans /= g;        len /= g;        printf("appx(%s,%s) = ", st1, st2);        if (ans == 0) puts("0");        else if (len == 1) printf("%dn", ans);        else printf("%d/%dn", ans, len);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/371019.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号