Skip to main content

AtCoder Beginner Contest 237(C - kasaka)

 

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

Popular posts from this blog

Codeforces Beta Round #53 (A. Square Earth?)

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 ...

Codeforces round 1676(A. Lucky?)

Just count the  first three  &  last three  number ///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 repres...

Codeforces round 1676(C. Most Similar Words)

  Just compare every pair distace such as  best & cost b & c => distace is 1 e & o => distace is 10 s & s => distace is 0 t & t => distace is 0 so the answer will be= (1+10+0+0) =11 ///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 d...