Applese 的回文串
生活随笔
收集整理的這篇文章主要介紹了
Applese 的回文串
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://ac.nowcoder.com/acm/contest/330/I
C++版本一
題解:
std
可以認為插入和刪除是等價的操作。想到這一點,這題就會好做很多。
如果這個串本身就是回文串,答案一定是Yes。
否則我們只需要考慮串中對稱的位置不相等的兩個字符,分別嘗試把它們刪掉后判斷一下是不是回文的就行了。
?C++版本二
/* *@Author: STZG *@Language: C++ */ #include <bits/stdc++.h> #include<iostream> #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio> #include<string> #include<vector> #include<bitset> #include<queue> #include<deque> #include<stack> #include<cmath> #include<list> #include<map> #include<set> //#define DEBUG #define RI register int using namespace std; typedef long long ll; //typedef __int128 lll; const int N=100000+10; const int MOD=1e9+7; const double PI = acos(-1.0); const double EXP = 1E-8; const int INF = 0x3f3f3f3f; int t,n,m,k,q; int ans,cnt,flag,temp; int a[N]; char str[N],tmp[N]; int main() { #ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout); #endifscanf("%s",str);//scanf("%d",&t);//while(t--){}int len=strlen(str);flag=0;for(int i=0;i<len;i++){if(str[i]!=str[len-i-1]){flag=1;cnt=i;}}if(flag){int l=0;for(int i=0;i<len;i++){if(i!=cnt){tmp[l++]=str[i];}}ans=0;for(int i=0;i<len-1;i++){if(tmp[i]!=tmp[len-i-2]){ans=1;}}if(ans){l=0;for(int i=0;i<len;i++){if(len-i-1!=cnt){tmp[l++]=str[i];}}ans=0;for(int i=0;i<len-1;i++){if(tmp[i]!=tmp[len-i-2]){ans=1;}}}if(ans){cout<<"No"<<endl;}else{cout<<"Yes"<<endl;}}else{cout<<"Yes"<<endl;}//cout << "Hello world!" << endl;return 0; }?
總結
以上是生活随笔為你收集整理的Applese 的回文串的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Applese 的大奖
- 下一篇: 炫酷双截棍