hdu 1306(字符串匹配)
来源:互联网 发布:安卓数据库 编辑:程序博客网 时间:2024/06/07 19:37
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1306
思路:一开始还以为是求最长公共序列呢。。。仔细一看,orz.....就是求两个串匹配时公共部分字符最多相同的个数。。。
View Code
1 #define _CRT_SECURE_NO_WARNINGS 2 #include<iostream> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 8 int gcd(int a,int b){ 9 return a%b==0?b:gcd(b,a%b);10 }11 12 13 int main(){14 char str1[1100],str2[1100];15 while(scanf("%s",str1),strcmp(str1,"-1")){16 scanf("%s",str2);17 int len1=strlen(str1);18 int len2=strlen(str2);19 int MAX=0,len=0;20 for(int i=0;i<len1;i++){21 for(int j=0;j<len2;j++){22 len=0;23 for(int k1=i,k2=j;k1<len1&&k2<len2;k1++,k2++){24 if(str1[k1]==str2[k2])len++;25 }26 if(len>MAX)MAX=len;27 }28 }29 if(MAX==0)printf("appx(%s,%s) = 0\n",str1,str2);30 else {31 int len=len1+len2;32 MAX*=2;33 int x=gcd(MAX,len);34 if(MAX==len){35 printf("appx(%s,%s) = 1\n",str1,str2);36 }else 37 printf("appx(%s,%s) = %d/%d\n",str1,str2,MAX/x,len/x);38 }39 }40 return 0;41 }
0 0
- hdu 1306(字符串匹配)
- hdu 2572 终曲(字符串匹配)
- HDU 1711(KMP)字符串匹配
- hdu 1238 字符串匹配
- HDU 1686 Kmp(字符串匹配)
- HDU 2087___kmp 字符串匹配
- HDU 2087 剪花布条(字符串匹配KMP)
- hdu 2222 Keywords Search(字符串匹配-AC自动机)
- HDU 5745 La Vie en rose 字符串匹配(暴力)
- kmp算法(字符串匹配 next应用 hdu题目集合)
- 字符串匹配(strstr)—— Bazinga ( HDU 5510 )
- HDU 5918 Sequence I (水题+字符串匹配)
- HDU 6208:The Dominator of Strings(字符串匹配)
- 字符串匹配(暴力匹配)
- HDU 1075 字典树 字符串匹配
- hdu 1711 KMP算法,字符串匹配
- HDU 1711 Number Sequence(字符串匹配)
- HDU - 1711 Number Sequence KMP字符串匹配
- hdu 1172(模拟、枚举)
- hdu 1237(模拟栈、水题)
- hdu 1296(多项式模拟)
- hdu 1302(简单模拟题)
- hdu 2832(数学题)
- hdu 1306(字符串匹配)
- NBU 1409(模拟题)
- hdu 1423(最长公共递增子序列)
- 黑色毛衣
- fzu校赛B题
- hdu 1496(hash经典)
- hdu 1270
- cf1b(字符串)
- hdu 1409