fork(12) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <time.h>
  6. #include <math.h>
  7.  
  8. #define INF 1<<30
  9. #define SZ 100000
  10.  
  11. char a[350], b[350], c[700], d[10], ans[310][310];
  12.  
  13. int strcheck(char *a,char *b)
  14. {
  15. int i=0;
  16. while(a[i]==b[i]) i++;
  17. return i;
  18. }
  19.  
  20. int cmp(const void *a,const void *b)
  21. {
  22. return strcmp(c+*(int *)a,c+*(int *)b);
  23. }
  24.  
  25. int main()
  26. {
  27. int i,j,k,l,m,n,t,x,y,tmp,max,blank=0,test=0,flag,suff[700];
  28. while(scanf("%s %s",a,b)!=EOF)
  29. {
  30. if(blank) putchar('\n');
  31. blank=1;
  32. x=strlen(a), y=strlen(b);
  33. strcpy(c,a);
  34. strcat(c,"#");
  35. strcat(c,b);
  36. for(i=0,l=x+y;i<=l;i++) suff[i]=i;
  37. qsort(suff,l+1,sizeof(int),&cmp);
  38. for(i=max=flag=n=0;i<l;i++)
  39. {
  40. if((suff[i]<x && suff[i+1]>x) || (suff[i]>x && suff[i+1]<x))
  41. {
  42. if((tmp=strcheck(c+suff[i],c+suff[i+1]))>max)
  43. {
  44. flag=1;
  45. strncpy(ans[n=0],c+suff[i],tmp);
  46. ans[0][tmp]=0;
  47. max=tmp;
  48. }
  49. else if(tmp==max)
  50. {
  51. strncpy(ans[++n],c+suff[i],tmp);
  52. ans[n][tmp]=0;
  53. }
  54. }
  55. }
  56. if(!flag) printf("No common sequence.\n");
  57. else for(i=0;i<=n;i++) puts(ans[i]);
  58. }
  59. return 0;
  60. }
  61.  
Success #stdin #stdout 0.01s 2772KB
stdin
Standard input is empty
stdout
Standard output is empty