s-palindrome

D - s-palindrome
Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.

English alphabet

You are given a string s. Check if the string is "s-palindrome".

Input

The only line contains the string s (1 ≤ |s| ≤ 1000) which consists of only English letters.

Output

Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.

Sample Input

Input
oXoxoXo
Output
TAK
Input
bod
Output
TAK
Input
ER
Output
NIE

大概题意就是:轴对称的字符串输出TAK ,否则输出ER


#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int len=s.size();
    char c[19][2]={'A','A','b','d','d','b','H','H','I','I','M','M','O','O','o',
    'o','p','q','q','p','U','U','V','V','v','v','W','W','w','w','X','X','x','x','Y','Y','T','T'};
    int flag=0;
    for(int i=0;i<=len/2;i++)
    {
        int fg=0;
        for(int j=0;j<19;j++)
        {
            if(s[i]==c[j][0]&&s[len-i-1]==c[j][1])
            {
                fg=1;
                break;
            }
        }
        if(fg==0)
        {
            puts("NIE");
            flag=1;
            break;
        }
    }
    if(flag==0) puts("TAK");
    return 0;
}
岂能尽如人意,但求无愧我心

### 题目分析 CSES - 1755 Palindrome Reorder 问题通常是给定一个字符串,要求判断是否可以将该字符串的字符重新排列形成一个回文串,如果可以,则输出重新排列后的回文字符串;如果不可以,则输出 "NO SOLUTION"。 ### 解决方案思路 要形成一个回文串,对于字符串中的字符,最多只能有一个字符的出现次数为奇数,其余字符的出现次数都必须为偶数。可以按照以下步骤解决该问题: 1. 统计字符串中每个字符的出现次数。 2. 检查出现次数为奇数的字符的数量。如果数量大于 1,则无法形成回文串,输出 "NO SOLUTION"。 3. 如果可以形成回文串,构建回文串。先将出现次数为偶数的字符分成两部分,分别放在回文串的左右两侧,然后将出现次数为奇数的字符放在回文串的中间。 ### 代码实现(Python) ```python # 读取输入的字符串 s = input() # 统计每个字符的出现次数 char_count = {} for char in s: if char in char_count: char_count[char] += 1 else: char_count[char] = 1 # 检查出现次数为奇数的字符的数量 odd_count = 0 odd_char = '' for char, count in char_count.items(): if count % 2 != 0: odd_count += 1 odd_char = char # 如果出现次数为奇数的字符数量大于 1,则无法形成回文串 if odd_count > 1: print("NO SOLUTION") else: # 构建回文串 left_half = '' for char, count in char_count.items(): left_half += char * (count // 2) # 输出回文串 result = left_half + odd_char + left_half[::-1] print(result) ``` ### 复杂度分析 - **时间复杂度**:$O(n)$,其中 $n$ 是字符串的长度。主要时间开销在于统计字符出现次数和构建回文串。 - **空间复杂度**:$O(k)$,其中 $k$ 是字符集的大小。主要空间开销在于存储每个字符的出现次数。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值