uva 644 Immediate Decodability(字符串比对)
2014-06-20 20:19
239 查看
题意是找出编码中是否存在一个编码是另一个编码的前缀。
利用排序的性质,排在前面的肯定是短的,即为前缀。
代码:
利用排序的性质,排在前面的肯定是短的,即为前缀。
代码:
#include <stdio.h> #include <stdlib.h> #include <string.h> char str[1000][100]; int min(int a, int b) { return a > b ? b : a; } int cmp(void const *va, void const *vb) { char *a = (char*)va; char *b = (char*)vb; return strcmp(a, b); } bool is_decode(int n) { int i, j; for (i = 1; i < n; i++) { int m = min(strlen(str[i - 1]), strlen(str[i])); for (j = 0; j < m; j++) { if (str[i - 1][j] != str[i][j]) break; } if (j == m) return false; } return true; } int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); #endif // LOCAL int ncase = 1; while (scanf("%s", str[0]) != EOF) { int i = 1; while (scanf("%s", str[i]) && str[i][0] != '9') i++; qsort(str, i, sizeof(str[0]), cmp); if (is_decode(i)) printf("Set %d is immediately decodable\n", ncase++); else printf("Set %d is not immediately decodable\n", ncase++); } return 0; }
相关文章推荐
- UVA 644(字符串)
- UVA 644 - Immediate Decodability(字符串)
- uva644-字符串
- uva644-字符串
- 字符串训练 ----- UVA 644题目 Immediate Decodability
- UVA 644 (暑假-字符串(2)-E - Immediate Decodability)
- UVa644-Immediate Decodability-字符串-难度2
- uva 644(字符串)
- Immediate Decodability - UVa 644 字符串处理
- uva 644 Immediate Decodability(字符串处理)
- UVALive 4513 Stammering Aliens 字符串Hash求LCS
- UVa 10391 - Compound Words (字符串hash)
- UVA 10905- Children's Game(sort处理string字符串)
- shell中if条件字符串、数字比对,[[ ]]和[ ]区别
- Excuses, Excuses! UVa409 字符串
- UVA10815 Andy's First Dictionary(字符串)
- UVa 11151 - Longest Palindrome 字符串dp
- uva 327(字符串)
- UVa 455 Periodic Strings(周期字符串)
- 对于过长字符串的大小比对