当前位置: 首页 > news >正文

POJ 1226 Substrings 解题报告

1.链接地址:http://poj.org/problem?id=1226

2.题目:

Substrings
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 10252 Accepted: 3519

Description

You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings.

Input

The first line of the input contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer n (1 <= n <= 100), the number of given strings, followed by n lines, each representing one string of minimum length 1 and maximum length 100. There is no extra white space before and after a string.

Output

There should be one line per test case containing the length of the largest string found.

Sample Input

2
3
ABCD
BCDFF
BRCD
2
rose
orchid

Sample Output

2
2 

Source

Tehran 2002 Preliminary

3.代码:

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstdlib>
 4 #include <cstring>
 5 #include <string.h>
 6 using namespace std;
 7 const int NUM = 100;
 8 char strs[NUM][NUM + 1];
 9 int main()
10 {
11     //freopen("F:\\input.txt","r",stdin);
12     
13     int t;
14     cin>>t;
15     
16     int n,length;
17     while(t--)
18     {
19         cin>>n;
20         cin.get();
21         
22         for(int i = 0; i < n; i++)
23         {
24             scanf("%s",strs[i]);
25         }
26         
27         for(int i = 0; i < n; i++)
28 
29         length = strlen(strs[0]);
30         char substr[NUM + 1],substr2[NUM + 1];
31         int res = 0;
32         for(int i = 1; i <= length; i++)
33         {
34             for(int j = 0; (j+i-1) < length; j++)
35             {
36                 strncpy(substr,&strs[0][j],i);
37                 substr[i] = '\0';
38                 strcpy(substr2,substr);
39                 
40                 for(int k = 0; k < (i+1)/2; k++)
41                 {
42                     char tmp = substr2[k];
43                     substr2[k] = substr2[i-1-k];
44                     substr2[i-1-k] = tmp;
45                 }
46                 
47                 
48                 //cout<<"substr="<<substr<<",substr2="<<substr2<<endl;
49                 int k;
50                 for(k = 1; k < n; k++)
51                 {
52                     if(!strstr(strs[k],substr) && !strstr(strs[k],substr2)) break;
53                 }
54                 if(k >= n ) 
55                 {
56                     res = i;
57                     break;
58                 }
59             }
60         }
61         
62         cout<<res<<endl;
63     }
64     return 0;
65 }

4.思路:

1.遍历所有的可能串,在查找是否符合。效率不是一般的差,不过对付这个简单还是可以的

2.看见书里推荐用strrev,但是无论是G++,C++都没有这个函数

转载于:https://www.cnblogs.com/mobileliker/archive/2013/05/27/3102105.html

相关文章:

  • 集合元素并查集
  • PostgreSQL的总体架构
  • Web 应用程序项目 XXXX 已配置为使用 IIS。 无法访问 IIS 元数据库。您没有足够的特权访问计算机上的 IIS 网站。...
  • 030、 Linux 查看CPU信息、机器型号等硬件信息
  • 用Shell脚本监控服务器并发邮件报警
  • HANA学习笔记1-搭建HANA学习环境
  • linux何检查一个目录是否为空目录
  • 网站安全那些事
  • Gartner:数据审计与保护的9个关键能力
  • Mybatis 在CS程序中的应用
  • 支持高并发的IIS Web服务器常用设置
  • ThinkPHP框架中添加404错误页面以及访问安全
  • 一条if语句引起的思考
  • SQLSERVER使用密码加密备份文件以防止未经授权还原数据库
  • Eclipse初次java开发问题总结-1
  • Apache Zeppelin在Apache Trafodion上的可视化
  • - C#编程大幅提高OUTLOOK的邮件搜索能力!
  • Javascripit类型转换比较那点事儿,双等号(==)
  • Webpack 4 学习01(基础配置)
  • 爱情 北京女病人
  • 从零开始的webpack生活-0x009:FilesLoader装载文件
  • 如何在 Tornado 中实现 Middleware
  • 使用putty远程连接linux
  • 吐槽Javascript系列二:数组中的splice和slice方法
  • 小程序 setData 学问多
  • 一个6年java程序员的工作感悟,写给还在迷茫的你
  • 赢得Docker挑战最佳实践
  • 源码安装memcached和php memcache扩展
  • 回归生活:清理微信公众号
  • ​​​​​​​ubuntu16.04 fastreid训练过程
  • ​批处理文件中的errorlevel用法
  • !! 2.对十份论文和报告中的关于OpenCV和Android NDK开发的总结
  • # 达梦数据库知识点
  • #!/usr/bin/python与#!/usr/bin/env python的区别
  • #QT(一种朴素的计算器实现方法)
  • #我与Java虚拟机的故事#连载17:我的Java技术水平有了一个本质的提升
  • (6)添加vue-cookie
  • (Java数据结构)ArrayList
  • (八)Spring源码解析:Spring MVC
  • (七)c52学习之旅-中断
  • (数位dp) 算法竞赛入门到进阶 书本题集
  • (四)linux文件内容查看
  • (转)ObjectiveC 深浅拷贝学习
  • (转)如何上传第三方jar包至Maven私服让maven项目可以使用第三方jar包
  • .NET Framework Client Profile - a Subset of the .NET Framework Redistribution
  • .NET Framework 和 .NET Core 在默认情况下垃圾回收(GC)机制的不同(局部变量部分)
  • .NET Standard、.NET Framework 、.NET Core三者的关系与区别?
  • .NET 的静态构造函数是否线程安全?答案是肯定的!
  • .NET 跨平台图形库 SkiaSharp 基础应用
  • .net 生成二级域名
  • .NET/C# 在代码中测量代码执行耗时的建议(比较系统性能计数器和系统时间)
  • .NET/C# 中你可以在代码中写多个 Main 函数,然后按需要随时切换
  • [Android]通过PhoneLookup读取所有电话号码
  • [BZOJ1089][SCOI2003]严格n元树(递推+高精度)
  • [C#基础]说说lock到底锁谁?