poj 1580 String Matching 【字符串处理】
来源:互联网 发布:js图片点击弹出放大 编辑:程序博客网 时间:2024/05/18 00:46
/*题意:移动字符串一与另外的一个字符串匹配,找最多的匹配个数策略 暴力 就是将一个字符串固定,然后用另一个字符串从左往右来跟这一字符串来比较*/
#include <stdio.h>#include <string.h>#define M 10000char a[M], b[M];int gcd(int a, int b){if(b == 0) return a;else return gcd(b, a%b);}int main(){while(scanf("%s", a) != EOF){if(strcmp("-1", a) == 0) break;scanf("%s", b);int la = strlen(a);int lb = strlen(b);int max = 0;for(int i = 0; i < la; i ++){ //将第二个字符串固定,然后移动第一个字符串int temp = 0;for(int j = 0, k = i; j < lb&&k< la; j++, k++){if(a[k] == b[j]){++temp;}}if(max < temp) max = temp;}for(int i = 0; i < lb; i ++){ /*将第一个字符串固定,然后移动第二个字符串*/int temp = 0;for(int j = 0, k = i; j < la&&k<lb; j++, k++){if(a[j] == b[k]){++temp;}}if(max < temp) max = temp;}//printf("%d\n", max);max*=2;printf("appx(%s,%s) = ", a, b);if(max == 0) {printf("0\n");continue;}if(max == la+lb){printf("1\n");continue;}int temp = gcd(la+lb, max);//printf("%d\n", temp);printf("%d/%d\n", max/temp, (la+lb)/temp);}}题目链接http://poj.org/problem?id=1580
0 0
- poj 1580 String Matching 【字符串处理】
- poj 1580 String Matching
- POJ 1580 String Matching G++
- POJ 1580-String Matching(枚举)
- poj 1580 String Matching(比较字符串的相似程度,四个for循环即可)
- poj String Matching
- 字符串匹配(String Matching)
- 【字符串】poj1582 String Matching
- Binary String Matching【暴力枚举】【字符串的处理】
- POJ 1580 String Matching(我的水题之路——字符串公共子串的比较雏形)
- poj 1580 String Matching【gcd辗转相除法】
- POJ 1580 && HDU 1306 String Matching(水~)
- PKU 1580 String Matching
- 字符串匹配(String matching)[No. 76]
- NYOJ 5 Binary String Matching 字符串匹配
- POj 1580(字符串处理)
- KMP Matching: String Matching
- String Matching
- 虚拟机与主机无法拷贝解决方法,VMware-tools安装
- quick-cocos2d-x游戏开发【6】——制作自定义效果按钮菜单
- 注解
- 7.11 字符串
- PEGA设计黄金十法则(翻译) ---- RoyZhang
- poj 1580 String Matching 【字符串处理】
- Android学习——TouchEvent时间传递机制
- Object.defineProperty
- HDU 1754 I Hate It (线段树单点更新)
- js如何获取到当前年份 和当前的年份-1
- QT学习随笔---信号槽
- Linux模块中使用socket网络通信 client部分
- 天龙服务器代码分析
- How to manually create a crash dump file