結果
| 問題 |
No.273 回文分解
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-26 17:51:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,004 bytes |
| コンパイル時間 | 555 ms |
| コンパイル使用メモリ | 57,240 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-25 13:33:37 |
| 合計ジャッジ時間 | 1,522 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 32 |
ソースコード
#include <iostream>
#include <string>
using namespace std;
int SearchPalidrome(string, int);
int main(int argc, const char * argv[]) {
string sentence;
int maxLength = 0;
cin >> sentence;
for (int i = 0; i < sentence.length() - 1; i++){
for (int j = i; j < sentence.length(); j++) {
string temp =sentence.substr(i, sentence.length() - j);
int num = SearchPalidrome(temp, 0);
if(num == sentence.length())
num -= 2;
if (num > maxLength)
maxLength = num;
}
}
cout << maxLength << endl;
return 0;
}
int SearchPalidrome(string sentence, int layer) {
if (sentence.length()== 1)
return ++layer;
if (sentence.length()== 0)
return layer;
if (sentence[0] == sentence[sentence.length() - 1]) {
string temp =sentence.substr(1, sentence.length() - 2);
return SearchPalidrome(temp, layer += 2);
}
return 0;
}