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

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

PAT甲級(jí)1040

2019-11-10 22:50:30
字體:
供稿:網(wǎng)友

1040. Longest Symmetric String (25)

時(shí)間限制400 ms內(nèi)存限制65536 kB代碼長(zhǎng)度限制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;			}		}	}//邊界	 //狀態(tài)轉(zhuǎn)移方程	for (int L = 3; L <= len; L++)//枚舉子串的長(zhǎng)度	{		for (int i = 0; i+L-1< len; i++)//枚舉子串的起始端點(diǎn),注意判斷右端點(diǎn)的范圍		{			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;}
上一篇:Golang API 類型 Get

下一篇:exit和atexit

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 重庆市| 桓仁| 庆城县| 嫩江县| 正阳县| 方山县| 凤阳县| 永州市| 杭锦后旗| 桐柏县| 阜新| 长宁县| 昭苏县| 红河县| 新安县| 乾安县| 营口市| 日喀则市| 来凤县| 临沂市| 苏尼特右旗| 塘沽区| 临夏市| 阿克陶县| 平江县| 丰原市| 泗洪县| 田东县| 湘潭县| 太和县| 桃园市| 正安县| 孟连| 湄潭县| 济宁市| 清徐县| 青铜峡市| 阳西县| 措美县| 平安县| 红原县|