Codeforces Round #127 (Div. 2) A. LLPS

A. LLPS
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline.

You are given string s consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence.

We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk (1  ≤  p1 < p2 < ... < pk  ≤  |s|) a subsequence of string s = s1s2... s|s|, where|s| is the length of string s. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba".

String x = x1x2... x|x| is lexicographically larger than string y = y1y2... y|y| if either |x| > |y| and x1 = y1x2 = y2, ..., x|y| = y|y|, or there exists such number r (r < |x|r < |y|) that x1 = y1x2 = y2, ..., xr = yr and xr  +  1 > yr  +  1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post".

String s = s1s2... s|s| is a palindrome if it matches string rev(s) = s|s|s|s| - 1... s1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z".

Input

The only input line contains a non-empty string s consisting of lowercase English letters only. Its length does not exceed 10.

Output

Print the lexicographically largest palindromic subsequence of string s.

Sample test(s)
input
radar
output
rr
input
bowwowwow
output
wwwww
input
codeforces
output
s
input
mississipp
output
ssss
Note

Among all distinct subsequences of string "radar" the following ones are palindromes: "a", "d", "r", "aa", "rr", "ada", "rar", "rdr", "raar" and "radar". The lexicographically largest of them is "rr"

题意:给你一个字符串,求出用已给的字符串中的字符组成的字典序最大的回文字符串。当然,当字符串中的字符都相同时,且是字典序最大的字符,同时也满足了字符串是回文字符串的要求。

#include
#include
#include
#include
#include
using namespace std;
bool cmp(char a,char b)
{
    return a=0;i--)
       if(s[i]==s[i-1])
         printf("%c",s[i]);
       else
         break;
    printf("\n");
   }
     return 0;
 }


你可能感兴趣的:(C/C++,CF)