zoukankan      html  css  js  c++  java
  • poj1580

    简单题

    View Code
    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    
    #define maxn 105
    
    char 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()
    {
    //    freopen("t.txt", "r", stdin);
        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("%d\n", ans);
            else
                printf("%d/%d\n", ans, len);
        }
        return 0;
    }
  • 相关阅读:
    django ORM
    django扩展知识
    django视图层
    php常用四种算法
    文件操作函数
    PHP开发中数组操作大全
    php 字符 常用函数
    MySQL的WHERE语句中BETWEEN与IN的用法和他们的区别
    $_SERVER
    PHP魔术方法和魔术常量
  • 原文地址:https://www.cnblogs.com/rainydays/p/2861729.html
Copyright © 2011-2022 走看看