zjut 1208排列对称串

排列对称串  Time Limit:1000MS  Memory Limit:32768K

Description:

很多字串,有些是对称的,有些是不对称的,请将那些对称的字串按从小到大的顺序输出。字串先以长度论大小,如果长度相同,再以ASCII码值为大小标准。

Input:

输入数据中含有一些字串(1≤串长≤256)。

Output:

根据每个字串,输出对称的那些串,并且要求按从小到大的顺序输出。

Sample Input:

123321
123454321
123
321
sdfsdfd
121212
\\dd\

Sample Output:

123321
\\dd\123454321

#include <cstdio>

#include <iostream>

#include <string>

#include <set>

#include <algorithm>

#include <vector>

using namespace std;

bool Comp(const string &s1,const string &s2)

{     return s1.length()!=s2.length()    ?       s1.length()<s2.length()  : s1<s2;      }

int main()

{

vector<string>v;

string t,s;

while (cin>>s)

{

t=s;                                     //s 保存到 t ,,,,,  t 不会改变

//反转字符串,用来判断字符是否对称

reverse(t.begin(),t.end());                  //对称-----反转

if (t==s)                                             // 反转后的s------压栈进入  向量容器vector

{             v.push_back(s);         }

}

//    排序

sort(v.begin(),v.end(),Comp);

//输出向量中的所有元素

for (int i=0;i<v.size();i++)

{                   cout<<v[i]<<endl;               }

return 0;

}

zjut 1208排列对称串,布布扣,bubuko.com

时间: 2024-08-01 22:44:22

zjut 1208排列对称串的相关文章

UVa 11584 Partitioning by Palindromes(DP 最少对称串)

题意  判断一个串最少可以分解为多少个对称串   一个串从左往后和从右往左是一样的  这个串就称为对沉串 令d[i]表示给定串的前i个字母至少可以分解为多少个对称串  那么对于j=1~i   若(i,j)是一个对称串  那么有  d[i]=min(d[i],d[j-1]+1)   然后就得到答案了 #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N

HustOJ - 1020

1 #include<iostream> 2 #include<vector> 3 #include<string> 4 #include<algorithm> //reverse所在头文件 5 using namespace std; 6 bool Comp(const string &str1,const string &str2) 7 { 8 if (str1.length()!=str2.length()) 9 return str1

zjut 1204 01串排序

01串排序  Time Limit:1000MS  Memory Limit:32768K Description: 将01串首先按长度排序,长度相同时,按1的个数多少进行排序,1的个数相同时再按ASCII码值排序. Input: 输入数据中含有一些01串,01串的长度不大于256个字符. Output: 重新排列01串的顺序.使得串按基本描述的方式排序. Sample Input: 10011111 00001101 1010101 1 0 1100 Sample Output: 0 1 11

leetcode-Symmetric Tree 对称树

Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree is symmetric: 1 / 2 2 / \ / 3 4 4 3 But the following is not: 1 / 2 2 \ 3 3 方法一: 层次遍历是最直观的方法.对数进行层次遍历,记录每一层的节点,然后对每一层的value组成

PTA——最长对称子串

PTA 7-64 最长对称子串 1 //流程: 2 //数组存储字符串,指针i从头遍历 3 //str[i-2]==str[i],若相等则记录对称串的长度,同时指针j从i-2开始向后遍历 4 //两个指针所指内容不相等时停止遍历,更新对称串的长度 5 //奇数情况// 6 //变量: 7 //字符数组str 8 //指针i.j 9 //状态变量sys——当前对称串是否在增长 10 //temp——当前对称串长度 11 // lng——当前最长对称串长度 12 //细节: 13 //i从2开始遍历

ACM——01排序

http://acm.njupt.edu.cn/acmhome/problemdetail.do?&method=showdetail&id=1024 01排序 时间限制(普通/Java):1000MS/3000MS          运行内存限制:65536KByte总提交:708            测试通过:258 描述 将01串首先按长度排序,长度相同时,按1的个数多少进行排序,1的个数相同时再按ASCII码值排序. 输入 输入数据中含有一些01串,01串的长度不大于256个字符

CodeForces - 748D Santa Claus and a Palindrome (贪心+构造)

题意:给定k个长度为n的字符串,每个字符串有一个魅力值ai,在k个字符串中选取字符串组成回文串,使得组成的回文串魅力值最大. 分析: 1.若某字符串不是回文串a,但有与之对称的串b,将串a和串b所有的魅力值分别从大到小排序后,若两者之和大于0,则可以放在回文串的两边. 2.若某字符串是回文串,将其魅力值从大到小排序后,两两依次分析:(mid---可能放在回文串中间的串的最大魅力值) (1)若两个数都是正的,那么就将其放在两边,并将结果计入ans.(ans---回文串两边的串的魅力值之和) (2)

L【leetcode】ongest Palindromic Substring

Longest Palindromic Substring Given a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic substring. Hide Tags String 利用DP思想做 dp[i][j]表示了第字符串中,s[i

KMP算法中的next[]数组

KMP算法最难懂的就是next[]数组的求法. 用一个例子来解释,下面是一个子串的next数组的值,可以看到这个子串的对称程度很高,所以next值都比较大. 位置i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 前缀next[i] 0 0 0 0 1 2 3 1 2 3 4 5 6 7 4 0 子串 a g c t a g c a g c t a g c t g 申明一下:下面说的对称不是中心对称,而是中心字符块对称,比如不是abccba,而是abcabc这种对称.