• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 21, comments - 2, trackbacks - 0, articles - 0

            ZOJ 1170--String Matching

            Posted on 2011-05-12 10:23 acpeng 閱讀(381) 評論(0)  編輯 收藏 引用 所屬分類: ACM程序

            OJ地址: There are lots of techniques for approximate word matching. One is to determine the best substring match, which is the number of common letters when the words are compared letter-byletter.
            The key to this approach is that the words can overlap in any way. For example, consider the words CAPILLARY and MARSUPIAL. One way to compare them is to overlay them:

            CAPILLARY
            MARSUPIAL

            There is only one common letter (A). Better is the following overlay:

            CAPILLARY
                 MARSUPIAL

            with two common letters (A and R), but the best is:

               CAPILLARY
            MARSUPIAL

            Which has three common letters (P, I and L).

            The approximation measure appx(word1, word2) for two words is given by:

                 common letters * 2
            -----------------------------
            length(word1) + length(word2)

            Thus, for this example, appx(CAPILLARY, MARSUPIAL) = 6 / (9 + 9) = 1/3. Obviously, for any word W appx(W, W) = 1, which is a nice property, while words with no common letters have an appx value of 0.
            Input:
            The input for your program will be a series of words, two per line, until the end-of-file flag of -1.
            Using the above technique, you are to calculate appx() for the pair of words on the line and print the result. For example:

            CAR CART
            TURKEY CHICKEN
            MONEY POVERTY
            ROUGH PESKY
            A A
            -1

            The words will all be uppercase.
            Output:
            Print the value for appx() for each pair as a reduced fraction, like this:

            appx(CAR,CART) = 6/7
            appx(TURKEY,CHICKEN) = 4/13
            appx(MONEY,POVERTY) = 1/3
            appx(ROUGH,PESKY) = 0
            appx(A,A) = 1

            Fractions reducing to zero or one should have no denominator

            代碼:

             1 /*
             2 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1170
             3 2011.5.12
             4 */
             5 #include<stdio.h>
             6 #include<string.h>
             7 int main()
             8 {
             9     int i,j,k,lgth1,lgth2,num,max,tmp1,tmp2,flg;
            10     char str1[1000]="\0",str2[1000]="\0";
            11     while(1)
            12     {
            13         scanf("%s",str1);
            14         if(strcmp(str1,"-1")==0)break;
            15         scanf("%s",str2);
            16         num=0; max=0;
            17         lgth1=(int)strlen(str1);
            18         lgth2=(int)strlen(str2);
            19         for(k=0;k<lgth1;k++)
            20         {
            21             j=0;
            22             for(i=k;i<lgth1 && j<lgth2;i++,j++)
            23                 if(str1[i]==str2[j])num++;
            24             if(max<num) max=num;
            25             num=0;
            26         }
            27         num=0;
            28         for(k=0;k<lgth2;k++)
            29         {
            30             j=0;
            31             for(i=k;i<lgth2 && j<lgth1;i++,j++)
            32                 if(str2[i]==str1[j])num++;
            33                     
            34             if(max<num) max=num;
            35             num=0;
            36         }
            37         printf("appx(%s,%s) = ",str1,str2);
            38 
            39         //化簡分式
            40         if(max==0) printf("0\n");
            41         else if(max*2 == lgth1+lgth2) printf("1\n");
            42         else
            43         {
            44             tmp1=max*2;tmp2=lgth1+lgth2;
            45             while(1)
            46             {
            47                 flg=0;
            48                 for(i=2;i<=tmp1;i++)
            49                 {
            50                     if(tmp1%i==0 && tmp2%i==0)
            51                     {
            52                         tmp1=tmp1/i; tmp2=tmp2/i;
            53                         flg=1;
            54                         break;
            55                     }
            56                 }
            57                 if(flg==0break;
            58             }
            59             printf("%d/%d\n",tmp1,tmp2);
            60         }
            61         memset(str1,0,sizeof(str1));
            62         memset(str2,0,sizeof(str2));
            63     }
            64     return 0;
            65 }
            久久er国产精品免费观看2| 综合人妻久久一区二区精品| 免费观看久久精彩视频| 久久精品国产91久久综合麻豆自制| 777久久精品一区二区三区无码| 精品久久久久久国产免费了| 亚洲国产成人精品久久久国产成人一区二区三区综 | 久久无码人妻一区二区三区午夜 | 久久精品一区二区三区中文字幕| 久久久久久毛片免费看| 人妻无码中文久久久久专区| 国产亚州精品女人久久久久久 | 国产精品久久午夜夜伦鲁鲁| 久久青青草原亚洲av无码| 欧美va久久久噜噜噜久久| 国产精品gz久久久| 国内精品久久久人妻中文字幕| 精品久久久久久无码人妻蜜桃| 久久久久久亚洲精品成人| 亚洲国产成人久久一区WWW| 精品国产91久久久久久久| 久久久久亚洲av综合波多野结衣| 久久精品国产一区二区电影| 国产成人精品久久二区二区| 色综合久久久久久久久五月| 欧美伊人久久大香线蕉综合| 久久精品国产精品亜洲毛片| 91超碰碰碰碰久久久久久综合| 7777久久亚洲中文字幕| 99精品久久精品一区二区| 欧美激情一区二区久久久| 久久天天躁狠狠躁夜夜不卡| 久久国产福利免费| 久久99精品久久久久久野外 | 无码人妻久久一区二区三区蜜桃 | 天堂久久天堂AV色综合| 精品综合久久久久久97| 亚洲а∨天堂久久精品| 亚洲精品tv久久久久久久久久| 三级片免费观看久久| 伊人久久大香线蕉AV一区二区|