- Get link
- X
- Other Apps
memory limit per test
256 megabytes
input
standard input
output
standard output
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Solution:
A. Mike and palindrome
memory limit per test
256 megabytes
input
standard input
output
standard output
Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome.
A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not.
Input
The first and single line contains string s (1 ≤ |s| ≤ 15).
Output
Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise.
Examples
input
Copy
abccaa
output
Copy
YES
input
Copy
abbcca
output
Copy
NO
input
Copy
abcda
output
Copy
YES
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin>>s;
int ans=0;
int d=s.length()/2 ;
//s.reverse( );
int i=0;
while(d-- )
{
if(s[i]!=s[s.length()-1-i])
ans++;
i++;
}if(ans==0 and s.length()%2==1) cout<<"YES";
else if(ans==1 ) cout<<"YES";
else cout<<"NO";
//cout<<ans;
}
- Get link
- X
- Other Apps
Comments
Post a Comment