nyoj 308 Substring
来源:互联网 发布:淘宝网闲鱼在哪里 编辑:程序博客网 时间:2024/04/28 17:54
Substring
时间限制:1000 ms | 内存限制:65535 KB
难度:1
- 描述
You are given a string input. You are to find the longest substring of input such that the reversal of the substring is also a substring of input. In case of a tie, return the string that occurs earliest in input.
Note well: The substring and its reversal may overlap partially or completely. The entire original string is itself a valid substring . The best we can do is find a one character substring, so we implement the tie-breaker rule of taking the earliest one first.
- 输入
- The first line of input gives a single integer, 1 ≤ N ≤ 10, the number of test cases. Then follow, for each test case, a line containing between 1 and 50 characters, inclusive. Each character of input will be an uppercase letter ('A'-'Z').
- 输出
- Output for each test case the longest substring of input such that the reversal of the substring is also a substring of input
- 样例输入
3 ABCABAXYZXCVCX
- 样例输出
ABAXXCVCX
#include<stdio.h> #include<string.h> int main() { int n,i,j,len,k,max; char a[55],b[55],c[55][55]; scanf("%d",&n); while(n--) { max=0; memset(c,0,sizeof(c)); getchar(); scanf("%s",a); len=strlen(a); for(i=0;i<len;i++) b[i]=a[len-i-1]; for(i=1;i<=len;i++) for(j=1;j<=len;j++) if(a[i-1]==b[j-1]) { c[i][j]=c[i-1][j-1]+1; if(c[i][j]>max) { max=c[i][j]; k=i; } } for(i=k-max;i<k;i++) printf("%c",a[i]); printf("\n"); } return 0; }
0 0
- NYOJ 308 Substring
- NYOJ 308题 Substring
- nyoj-308-Substring
- nyoj 308 Substring
- nyoj 308 Substring
- nyoj 308 Substring
- NYOJ 308-Substring【模拟】
- NYOJ 308 Substring
- nyoj 308 Substring
- NYOJ Substring--308
- nyoj 308 Substring
- nyoj 308 Substring
- NYOJ 308 Substring
- NYOJ—308—Substring
- NYOJ - Substring
- NYOJ 308 Substring 字符串处理问题
- nyoj 308 substring (最长逆序字符串)
- nyoj 308-Substring(find 和 substr的用法)
- 国际化方案的思考——方案选型的重要性
- 使用内部(com.android.internal)和隐藏(@hide)API[第4部分,定制ADT]
- 在3D空间中绘制三角形
- 英国调查报告称中国梦吸引力首超美国梦
- 每天来点算法_1
- nyoj 308 Substring
- priority_queue用法
- PID1 / 明明的随机数 ☆
- java 利用String.trim()函数实现右侧去除空格
- 纯JS长文章分页代码
- BIOS密码清除方法--unlock6的使用.
- struct和union的区别
- 从用户体验看服务业的前途
- Python 3 在 UBUNTU/DEBIAN 系统上进行 MYSQL DATABASE SERVERS 备份