国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

PAT甲級1040

2019-11-10 23:04:50
字體:
來源:轉載
供稿:網友

1040. Longest Symmetric String (25)

時間限制400 ms內存限制65536 kB代碼長度限制16000 B判題程序Standard作者CHEN, Yue

Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given "Is PAT&TAP symmetric?", the longest symmetric sub-string is "s PAT&TAP s", hence you must output 11.

Input Specification:

Each input file contains one test case which gives a non-empty string of length no more than 1000.

Output Specification:

For each test case, simply PRint the maximum length in a line.

Sample Input:
Is PAT&TAP symmetric?Sample Output:
11
#include<iostream>#include<string>#include<algorithm>using namespace std;const int maxn = 1010;bool d[maxn][maxn] = { false };int main(){	string s;	getline(cin, s);	int len = s.size();	int ans = 1;	for (int i = 0; i < len; i++)	{		d[i][i] = true;		if (i < len - 1)		{			if (s[i] == s[i + 1])			{				d[i][i + 1] = true;				ans = 2;			}		}	}//邊界	 //狀態轉移方程	for (int L = 3; L <= len; L++)//枚舉子串的長度	{		for (int i = 0; i+L-1< len; i++)//枚舉子串的起始端點,注意判斷右端點的范圍		{			int j = i + L - 1;			if (s[i] == s[j] && d[i + 1][j - 1])			{				d[i][j] = true;				ans = L;			}		}	}	cout << ans << endl;	return 0;}
上一篇:PAT甲級1074

下一篇:查找第K大元素

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安阳市| 湘阴县| 冀州市| 蚌埠市| 招远市| 浪卡子县| 綦江县| 鄂托克前旗| 新余市| 敖汉旗| 泗水县| 即墨市| 贵南县| 水城县| 陆川县| 平阳县| 双城市| 金昌市| 炎陵县| 凌源市| 海丰县| 南汇区| 商丘市| 重庆市| 江华| 章丘市| 四会市| 彭阳县| 澎湖县| 子洲县| 昂仁县| 舟曲县| 万宁市| 高邮市| 乌拉特前旗| 文山县| 潜山县| 井冈山市| 怀集县| 兴安县| 榕江县|