To learn string:
function:https://www.cplusplus.com/reference/string/string/
palindrome:A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward.
abba--palindrome
mosque--not palindrome
At first need to check how many 'a' from the beginning and from the last then minus it and lastly check it is palindrome or not.
1.kasaka (first 'a'=0 & last 'a'=1) after erase last 1(1-0) 'a' kasak & check kasak is palindrome or not(palindrome)
2.atcoder (first 'a'=1 & last 'a'=0) after erase last 0(first>last) 'a' atcoder & check atcoder is palindrome or not(not palindrome)
3.php (first 'a'=0 & last 'a'=0) after erase last 0(0-0) 'a' php & check php is palindrome or not(palindrome)
4.apa (first 'a'=1 & last 'a'=1) after erase last 0(1-1) 'a' kasak & check kasak is palindrome or not(palindrome)
///Bismillahir Rahmanir Rahim
///Author:Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int main()
{
int fir=0,last=0;
string str;
cin>>str;
for(int i=0;i<(str.size());i++)
{
if(str[i]=='a') fir++;
else break;
}
for(int i=str.size()-1;i>=0;i--)
{
if(str[i]=='a') last++;
else break;
}
int dif=last-fir;
if(dif>=0)
{
int in=str.size()-dif;
str.erase(in,dif);
string rev=str;
reverse(rev.begin(),rev.end());
if(str==rev) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}
else cout<<"No"<<endl;
return 0;
}
///Alhamdulillah
Problem Link:https://atcoder.jp/contests/abc237/tasks/abc237_c
Comments
Post a Comment