日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

OpenJudge/Poj 1226 Substrings

發布時間:2023/12/9 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 OpenJudge/Poj 1226 Substrings 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1.鏈接地址:

http://bailian.openjudge.cn/practice/1226/

http://poj.org/problem?id=1226

2.題目:

總時間限制:
1000ms
內存限制:
65536kB
描述
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.
輸入
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.
輸出
There should be one line per test case containing the length of the largest string found.
樣例輸入
2 3 ABCD BCDFF BRCD 2 rose orchid
樣例輸出
2 2
來源
Tehran 2002 Preliminery

3.思路:

?

4.代碼:

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 int i,j,k; 13 14 int t; 15 cin>>t; 16 17 int n,length; 18 while(t--) 19 { 20 cin>>n; 21 cin.get(); 22 23 for(i = 0; i < n; i++) 24 { 25 scanf("%s",strs[i]); 26 } 27 28 for(i = 0; i < n; i++) 29 30 length = strlen(strs[0]); 31 char substr[NUM + 1],substr2[NUM + 1]; 32 int res = 0; 33 for(i = 1; i <= length; i++) 34 { 35 for(j = 0; (j+i-1) < length; j++) 36 { 37 strncpy(substr,&strs[0][j],i); 38 substr[i] = '\0'; 39 strcpy(substr2,substr); 40 41 for(k = 0; k < (i+1)/2; k++) 42 { 43 char tmp = substr2[k]; 44 substr2[k] = substr2[i-1-k]; 45 substr2[i-1-k] = tmp; 46 } 47 48 49 //cout<<"substr="<<substr<<",substr2="<<substr2<<endl; 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 }

?

轉載于:https://www.cnblogs.com/mobileliker/p/3551994.html

總結

以上是生活随笔為你收集整理的OpenJudge/Poj 1226 Substrings的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。