记录编号 |
190930 |
评测结果 |
AWAAAWE |
题目名称 |
基本的回文串练习 |
最终得分 |
57 |
用户昵称 |
DONGCI |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
0.100 s |
提交时间 |
2015-10-05 13:20:55 |
内存使用 |
10.08 MiB |
显示代码纯文本
- #include <iostream>
- using namespace std;
- #include <cstdio>
- #include <memory>
- #include <cstdlib>
- #include <cstring>
- const int N=503;
- char s[N];
- struct node{
- char c[N];
- int l;
- int left;
- }b[20000];
- int len;
-
- inline bool work(int l,int r){
- bool f=true;
- if(l==r)
- return false;
- for(int i=l,j=r;j>i;i++,j--){
- if(s[i]!=s[j]){
- f=false;
- break;
- }
- }
- if(f)return true;
- return false;
- }
-
- inline int cmp(const void *a,const void *b){
- struct node x=*(struct node *)a;
- struct node y=*(struct node *)b;
- if(x.l<y.l)
- return -1;
- if(x.l==y.l)
- if(x.left<y.left)
- return -1;
- if(strcmp(x.c,y.c)<0)
- return -1;
- return 1;
- }
-
- int main()
- {
- freopen("erase.in","r",stdin);
- freopen("erase.out","w",stdout);
- scanf("%s",s);
- int l=strlen(s),i,j,k;
- for(i=0;i<l;i++)
- for(j=i+1;j<l;j++)
- if(work(i,j)){
- len++,b[len].left=i;
- for(k=i;k<=j;k++)
- b[len].c[++b[len].l]=s[k];
- }
- qsort(b+1,len,sizeof(b[1]),cmp);
- for(i=1;i<=len;i++){
- for(j=1;j<=b[i].l;j++)
- cout<<b[i].c[j];
- cout<<endl;
- }
- return 0;
- }