hdu 2572
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2572
题意:中文。
mark:直接暴搞。1wa,注意要取字母序最小的,长度要先判断。
代码:
1 # include <stdio.h> 2 # include <string.h> 3 4 5 char ans[110] ; 6 char s1[110], s2[110], s3[110] ; 7 char ss[110] ; 8 9 10 int find(char s[], char p[]) 11 { 12 int i, j, len1 = strlen(s), len2 = strlen(p) ; 13 for (i = 0 ; i < len1-len2+1 ; i ++) 14 { 15 for (j = 0 ; j < len2 ; j++) 16 if (s[i+j] != p[j]) break ; 17 if (j == len2) return 1 ; 18 } 19 return 0 ; 20 } 21 22 23 int test() 24 { 25 if (find(ss, s2) == 0) return 0 ; 26 if (find(ss, s3) == 0) return 0 ; 27 return 1 ; 28 } 29 30 31 int main () 32 { 33 int T, i, j ; 34 scanf ("%d", &T) ; 35 while (T--) 36 { 37 scanf ("%s%s%s", s1, s2, s3) ; 38 strcpy (ans, "No") ; 39 for (i = 0 ; s1[i] ; i++) 40 { 41 for (j = i ; s1[j] ; j++) 42 { 43 ss[j-i] = s1[j] ; 44 ss[j-i+1] = '\0' ; 45 if (test()) 46 { 47 if (strcmp(ans, "No") == 0 || strlen(ss) < strlen(ans) || strcmp(ss, ans)<0) 48 strcpy (ans, ss) ; 49 break ; 50 } 51 } 52 } 53 puts (ans) ; 54 } 55 return 0 ; 56 }