周赛B 又见回文串

题目链接:猛点

<span style="font-size:18px;">/*
  B 又见回文串
  理解了这道题时,我就笑了.完全没有难度啊.
  反思:为什么自己比赛时没有理解了这道题.题读的少吧?
       还有一看到自己没有学过的地方,就有点不敢下手吧.
       所以,再次遇见没有写过的,也要认真思考,真不行了,在放弃.
       当然,这只是在比赛的时候.
*/
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    while(cin>>s)
    {
        int c[27]={0},len=s.size();
        for(int i=0;i<len;i++)
        c[s[i]-'a']++;
        int num=0;
        for(int i=0;i<26;i++)
        if(c[i]%2) num++;
        if(num==0||num==1||num%2==0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}
</span>


//不知道,什么时候写的这道题,今天又拿来看来一下。

//好想是大一,大二时候的一个周赛题,个人觉的当时没有做出来,很有可能就是没有很清楚的读懂题意。


//其实这道题的关键在于,去掉一个字符后,其他字符重新排列。。这就和顺序上无关了,至于数量上有关。

//我们可以这么想,结果是一个回文,那么对应是可以删掉,只剩下单个。

比如,aabbccdefg = defg 这样来看是不是更简单了呢?

ac代码:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
using namespace std;

const int N = 10000 + 5;
const int M = 26 + 5;
int hash[M];
int main()
{
    char str[N];
    while(~scanf("%s", str)){
        int len = strlen(str);
        memset(hash, 0, sizeof(hash));
        for(int i = 0; i < len; i ++){
            hash[str[i] - 'a'] ++;
        }
        int cnt = 0;
        for(int i = 0; i < 26; i ++){
            if(hash[i] % 2) cnt ++;
        }
        if(cnt % 2 == 0 || cnt == 1){
            puts("Yes");
        }
        else puts("No");
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值