c_cpp 回文子序列 - GeeksforGeeks
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 回文子序列 - GeeksforGeeks相关的知识,希望对你有一定的参考价值。
/*
http://ideone.com/oUPCxR
http://www.geeksforgeeks.org/minimum-number-of-palindromic-subsequences-to-be-removed-to-empty-a-binary-string/
http://www.practice.geeksforgeeks.org/problem-page.php?pid=718
*/
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool isPalindrome(string s, int len){
int l = 0;
int h = len -1;
while(l < h){
if(s[l++] != s[h--])
return false;
}
return true;
}
int main() {
int t, n;
cin >> t;
while(t--){
string s;
cin >> n >> s;
if(isPalindrome(s, n))
cout << 1 << endl;
else
cout << 2 << endl;
}
return 0;
}
以上是关于c_cpp 回文子序列 - GeeksforGeeks的主要内容,如果未能解决你的问题,请参考以下文章