记录编号 190930 评测结果 AWAAAWE
题目名称 基本的回文串练习 最终得分 57
用户昵称 GravatarDONGCI 是否通过 未通过
代码语言 C++ 运行时间 0.100 s
提交时间 2015-10-05 13:20:55 内存使用 10.08 MiB
显示代码纯文本
  1. #include <iostream>
  2. using namespace std;
  3. #include <cstdio>
  4. #include <memory>
  5. #include <cstdlib>
  6. #include <cstring>
  7. const int N=503;
  8. char s[N];
  9. struct node{
  10. char c[N];
  11. int l;
  12. int left;
  13. }b[20000];
  14. int len;
  15.  
  16. inline bool work(int l,int r){
  17. bool f=true;
  18. if(l==r)
  19. return false;
  20. for(int i=l,j=r;j>i;i++,j--){
  21. if(s[i]!=s[j]){
  22. f=false;
  23. break;
  24. }
  25. }
  26. if(f)return true;
  27. return false;
  28. }
  29.  
  30. inline int cmp(const void *a,const void *b){
  31. struct node x=*(struct node *)a;
  32. struct node y=*(struct node *)b;
  33. if(x.l<y.l)
  34. return -1;
  35. if(x.l==y.l)
  36. if(x.left<y.left)
  37. return -1;
  38. if(strcmp(x.c,y.c)<0)
  39. return -1;
  40. return 1;
  41. }
  42.  
  43. int main()
  44. {
  45. freopen("erase.in","r",stdin);
  46. freopen("erase.out","w",stdout);
  47. scanf("%s",s);
  48. int l=strlen(s),i,j,k;
  49. for(i=0;i<l;i++)
  50. for(j=i+1;j<l;j++)
  51. if(work(i,j)){
  52. len++,b[len].left=i;
  53. for(k=i;k<=j;k++)
  54. b[len].c[++b[len].l]=s[k];
  55. }
  56. qsort(b+1,len,sizeof(b[1]),cmp);
  57. for(i=1;i<=len;i++){
  58. for(j=1;j<=b[i].l;j++)
  59. cout<<b[i].c[j];
  60. cout<<endl;
  61. }
  62. return 0;
  63. }