A. Mike and palindrome

Codeforces
IDCF798A
Time2000ms
Memory256MB
Difficulty
brute forceconstructive algorithmsstrings
English · Original
Chinese · Translation
Formal · Original
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. [samples]
Mike 有一个仅由小写英文字母组成的字符串 #cf_span[s]。他希望将字符串中的*恰好一个*字符进行修改,使得修改后的字符串成为回文串。 回文串是指正读和反读都相同的字符串,例如字符串 "_z_"、"_aaa_"、"_aba_"、"_abccba_" 是回文串,但字符串 "_codeforces_"、"_reality_"、"_ab_" 不是。 第一行且仅有一行包含字符串 #cf_span[s](#cf_span[1 ≤ |s| ≤ 15])。 如果 Mike 能够通过修改*恰好一个*字符使结果字符串成为回文串,则输出 "_YES_"(不含引号);否则输出 "_NO_"(不含引号)。 ## Input 第一行且仅有一行包含字符串 #cf_span[s](#cf_span[1 ≤ |s| ≤ 15])。 ## Output 如果 Mike 能够通过修改*恰好一个*字符使结果字符串成为回文串,则输出 "_YES_"(不含引号);否则输出 "_NO_"(不含引号)。 [samples]
**Definitions** Let $ s \in \Sigma^* $ be a string of length $ n $, where $ \Sigma = \{a, b, \dots, z\} $ and $ 1 \leq n \leq 15 $. **Constraints** 1. $ |s| = n $, with $ 1 \leq n \leq 15 $ 2. Each character of $ s $ is a lowercase English letter. **Objective** Determine whether there exists exactly one index $ i \in \{1, \dots, n\} $ and a character $ c \in \Sigma $ such that replacing $ s[i] $ with $ c $ yields a palindrome, and the resulting string is not identical to $ s $. Equivalently, define $ s' $ such that $ s'[j] = s[j] $ for all $ j \neq i $, and $ s'[i] = c \neq s[i] $, and $ s' $ is a palindrome. Output "YES" if such $ i $ and $ c $ exist; otherwise, output "NO".
Samples
Input #1
abccaa
Output #1
YES
Input #2
abbcca
Output #2
NO
Input #3
abcda
Output #3
YES
API Response (JSON)
{
  "problem": {
    "name": "A. Mike and palindrome",
    "description": {
      "content": "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 th",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF798A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "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.\n\nA palindrome is a string th...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Mike 有一个仅由小写英文字母组成的字符串 #cf_span[s]。他希望将字符串中的*恰好一个*字符进行修改,使得修改后的字符串成为回文串。\n\n回文串是指正读和反读都相同的字符串,例如字符串 \"_z_\"、\"_aaa_\"、\"_aba_\"、\"_abccba_\" 是回文串,但字符串 \"_codeforces_\"、\"_reality_\"、\"_ab_\" 不是。\n\n第一行且仅有一行包含字符串 #cf_sp...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ s \\in \\Sigma^* $ be a string of length $ n $, where $ \\Sigma = \\{a, b, \\dots, z\\} $ and $ 1 \\leq n \\leq 15 $.\n\n**Constraints**  \n1. $ |s| = n $, with $ 1 \\leq n \\leq 15 $  \n2. ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments