691B - s-palindrome - CodeForces Solution


implementation strings *1600

Please click on ads to support us..

Python Code:

import sys
input = lambda: sys.stdin.readline().strip()
s = input()

def bd_pq_swap(s):
    return ''.join(
        'p' if c == 'q' else
        'q' if c == 'p' else
        'b' if c == 'd' else
        'd' if c == 'b' else
        c
        for c in s
    )

mirrored = 'AbdHIMOopqTUVvWwXxY'
print('TAK' if s == ''.join(reversed(bd_pq_swap(s))) and all(c in mirrored for c in s) else 'NIE')

C++ Code:

// Problem: B. s-palindrome
// Contest: Codeforces - Educational Codeforces Round 14
// URL: https://codeforces.com/contest/691/problem/B
// Memory Limit: 256 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const int N = 2e5+5;

bool check(char c){
	string s="AHIMOoTUVvWwXxY";
	for(int i=0;i<s.size();i++){
		if(c==s[i]) return true;
	}
	return false;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);

	string a;
	cin>>a;
	
	bool flag=false;
	for(int i=0;i<a.size();i++){
		if(a[i]==a[a.size()-i-1]&&check(a[i])){
			flag=true;
		}
		else if((a[i]=='b'&&a[a.size()-i-1]=='d')||(a[i]=='p'&&a[a.size()-i-1]=='q')||(a[i]=='d'&&a[a.size()-i-1]=='b')||(a[i]=='q'&&a[a.size()-i-1]=='p')){
			flag=true;
		}
		else{
			cout<<"NIE\n";
			return 0;
		}
	}
	//cout<<a[ans]<<' '<<a[a.size()-ans-1]<<"\n";
	//cout<<ans<<" ";
	cout<<"TAK\n";
	
	return 0;	

}

   	    	 		 			 	   		 				  	


Comments

Submit
0 Comments
More Questions

630D - Hexagons
1690D - Black and White Stripe
1688D - The Enchanted Forest
1674C - Infinite Replacement
712A - Memory and Crow
1676C - Most Similar Words
1681A - Game with Cards
151C - Win or Freeze
1585A - Life of a Flower
1662A - Organizing SWERC
466C - Number of Ways
1146A - Love "A"
1618D - Array and Operations
1255A - Changing Volume
1710C - XOR Triangle
415C - Mashmokh and Numbers
8A - Train and Peter
591A - Wizards' Duel
1703G - Good Key Bad Key
1705A - Mark the Photographer
1707A - Doremy's IQ
1706B - Making Towers
1325B - CopyCopyCopyCopyCopy
1649C - Weird Sum
1324B - Yet Another Palindrome Problem
525A - Vitaliy and Pie
879A - Borya's Diagnosis
1672B - I love AAAB
1673A - Subtle Substring Subtraction
1345A - Puzzle Pieces