程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> POJ 1226 Substrings 解題報告

POJ 1226 Substrings 解題報告

編輯:C++入門知識

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.代碼:

 #include <iostream>
 #include <cstdio>
 #include <cstdlib>
 #include <cstring>
 #include <.h>
     NUM =   strs[NUM][NUM +        
     
          cin>>     
          (t--          cin>>         cin.         
         ( i = ; i < n; i++              scanf(          
         ( i = ; i < n; i++ 
         length = strlen(strs[          substr[NUM + ],substr2[NUM +           res =          ( i = ; i <= length; i++              ( j = ; (j+i-) < length; j++                  strncpy(substr,&strs[                 substr[i] =                   
                 ( k = ; k < (i+)/; k++                       tmp =                     substr2[k] = substr2[i--                     substr2[i--k] =                  
                 
                 
                                  (k = ; k < n; k++                      (!strstr(strs[k],substr) && !strstr(strs[k],substr2))                   (k >=                      res =                                 
         cout<<res<<        }

4.思路:

1.遍歷所有的可能串,在查找是否符合。效率不是一般的差,不過對付這個簡單還是可以的

2.看見書裡推薦用strrev,但是無論是G++,C++都沒有這個函數

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved