UVA 12718 Dromicpalin Substrings(寻找字符串连续子串的回文)
来源:互联网 发布:nginx 1.10 1.12 编辑:程序博客网 时间:2024/05/16 06:20
转载请注明出处:http://blog.csdn.net/u012860063
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4456
题意:寻找给出字符串的子串中是回文的个数(注意:字串中字母换位置后能组成回文也要算在内,例如:aab之类的可以换位置为:aba 也是一个回文)。
思路:只需统计每个字母出现的次数,再统计出现次数中为奇数的个数,如果某个子串中出现奇数次数的字母仅有一个或者没有,那么就符合题目要求!
代码如下:
#include <cstdio>#include <cstring>int main(){int t, cont, i, j;char s[1047];int c[47];int cas =0;while(~scanf("%d",&t)){getchar();while(t--){gets(s);int len = strlen(s);int k = len;for(i = 0; i < len; i++){cont = 1;memset(c,0,sizeof(c));c[s[i]-'a']++;for(j = i+1; j < len; j++){c[s[j]-'a']++;if((c[s[j]-'a'])%2 == 1)cont++;elsecont--;if(cont == 1 || cont == 0)//出现奇数次数的字母有一个或者没有k++;}}printf("Case %d: %d\n",++cas,k);}}return 0;}
2 0
- UVA 12718 Dromicpalin Substrings(寻找字符串连续子串的回文)
- UVA 12718 Dromicpalin Substrings
- UVA 12718 Dromicpalin Substrings
- 647. Palindromic Substrings(回文子字符串)
- Dromicpalin Substrings
- 寻找字符串中连续出现次数最多的子串
- UVA - 10617 Again Palindrome 字符串的回文子串
- 寻找一个字符串的所有回文子字符串
- hdoj 1238 Substrings(字符串的子串)
- leetcode 647. Palindromic Substrings 回文子串的数量
- HDU--1238-Substrings(-最长连续子串)
- 647. Palindromic Substrings 回文子串
- 用三重循环求一个字符串的最大回文串(连续重复出现的最长子串)
- UVALive 6659 Dromicpalin Substrings
- 寻找一个字符串中连续出现次数最多的子串
- 寻找一个字符串中连续出现次数最多的子串
- 寻找一个字符串中连续出现次数最多的子串
- 寻找一个字符串中连续出现次数最多的子串
- 微软这是把Android当QNX用啊
- Error starting command: monkey --port 12345 卡死的问题
- 华为初级——iNOC产品部:杨辉三角形的变形
- JAVA学习篇--静态代理VS动态代理
- 对SVM的理解
- UVA 12718 Dromicpalin Substrings(寻找字符串连续子串的回文)
- Linux中source命令的用法
- 后缀自动机的直观理解
- java把class类写入excel和读取出来的通用方法
- ERROR 1045 (28000): Access denied for user root@localhost (using password: YES)
- redis数据库的设计实例
- sqlite-5分钟入门手册
- [LeetCode]Single Number
- 「算法导论」:课后习题2.3-7求集合S中是否有两个元素的和为X