设为首页 加入收藏

TOP

poj 1580 String Matching(比较字符串的相似程度,四个for循环即可)
2015-07-20 17:50:44 来源: 作者: 【 】 浏览:2
Tags:poj 1580 String Matching 比较 字符串 相似 程度 四个 for 循环 即可
String Matching
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 3717 Accepted: 1913

Description

It's easy to tell if two words are identical - just check the letters. But how do you tell if two words are almost identical? And how close is "almost"?

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.
The words will all be uppercase.

Output

Print the value for appx() for each pair as a reduced fraction,Fractions reducing to zero or one should have no denominator.

Sample Input

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

Sample Output

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

Source

Pacific Northwest 1999 思路: 就是简单地 一个暴力遍历。 体会: 细节很重要,团队默契很重要。因为与队友的对题意理解的分歧,导致这道水题到最后愣是没有AC出来。虽说最后是我的理解正确,但是因为这个分歧,直接影响了团队配合的默契,还是要提高自身能力,提高团队配合力度。心向往之,行而不止。加油! 代码如下:
#include
  
   
#include
   
     int gcd(int a,int b) { return !b?a:gcd(b,a%b); } char a[1010],b[1010],temp[2022]; int main() { int i,j,i1,j1; while(~scanf("%s",a),strcmp(a,"-1")) { scanf("%s",b); int len1=strlen(a); int len2=strlen(b); int max=0; for(i=0;i
    
     

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇uva10626 - Buying Coke(记忆话搜.. 下一篇HDU 1045 Fire Net 二分图Biparti..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·switch520最新的地址 (2025-12-24 19:19:41)
·微信聊天功能使用了 (2025-12-24 19:19:39)
·websocket和普通的so (2025-12-24 19:19:36)
·Python中文网 - 人生 (2025-12-24 18:49:47)
·【整整648集】这绝对 (2025-12-24 18:49:44)