ZOJ-1170
2014-07-03 22:52
162 查看
由于数据量很小。。直接用最暴力的枚举了。。怎么简便怎么写
#include<stdio.h> #include<string.h> static int gcd(int a, int b) { if (!a) return b; return gcd(b % a, a); } int main() { char s[100], t[100]; while (scanf("%s", s), strcmp(s, "-1")) { scanf("%s", t); int i, j, k, l, max = 0, com; for (i = 0; s[i] != '\0'; i++) for (j = 0; t[j] != '\0'; j++) if (s[i] == t[j]) { k = i + 1; l = j + 1; com = 1; while (s[k] != '\0' && t[l] != '\0') { if (s[k] == t[l]) com++; k++; l++; } if (com > max) max = com; } int a = max * 2; int b = strlen(s) + strlen(t); printf("appx(%s,%s) = ", s, t); if (a == b) puts("1"); else if (!a) puts("0"); else { int g = gcd(a, b); printf("%d/%d\n", a / g, b / g); } } return 0; }
相关文章推荐
- zoj_1170
- ZOJ 1170 String Matching
- zoj1004 Anagrams by Stack
- zoj 2851 Code Formatter
- ZOJ 3612 && HDU 4864 (multiset 的应用)
- ZOJ 3362--Beer Problem【最大费用最大流 && 有值得注意的地方】
- ZOJ——1197 Sorting Slides
- zoj 2486 Power of Cryptography
- ZOJ 2104/HDU 1004 Let the Balloon Rise(map容器)
- [ACM] ZOJ 3725 Painting Storages (DP计数+组合)
- ZOJ 3641 Information Sharing
- ZOJ 3962 -- 数位dp
- ZOJ-1041-Transmitters
- ZOJ 3662 Math Magic (2012 Changchun Regional; LCM,DP)
- ZOJ 3720 Magnet Darts (计算几何,概率,判点是否在多边形内)
- zoj-3795-Grouping-tarjan确定最长的公路收缩
- ZOJ问题(2010浙江大学研究生复试上机题目[找规律] hdoj 3788)
- ZOJ-1067-Color Me Less
- zoj 2412 水田灌溉,求连通分支个数
- ZOJ Problem Set - 1383 Binary Numbers