CF122B.Lucky Substring

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

One day Petya was delivered a string s, containing only digits. He needs to find a string that

  • represents a lucky number without leading zeroes,
  • is not empty,
  • is contained in s as a substring the maximum number of times.

Among all the strings for which the three conditions given above are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.

佩佳喜欢幸运数字。众所周知,幸运数字是指其十进制表示中仅包含幸运数字 4 和 7 的正整数。例如,47、744、4 是幸运数字,而 5、17、467 则不是。

有一天,佩佳收到了一个只包含数字的字符串 ss。他需要找到一个字符串,满足以下条件:

  • 它表示一个不含前导零的幸运数字;
  • 它非空;
  • 作为子串在 ss 中出现的次数最多。

在所有满足上述三个条件的字符串中,佩佳只需要字典序最小的那个。请为佩佳找出这个字符串。

输入格式

The single line contains a non-empty string s whose length can range from 1 to 50, inclusive. The string only contains digits. The string can contain leading zeroes.

单行输入包含一个非空字符串 ss,其长度在 11 到 5050(含)之间。该字符串仅由数字组成,且可能包含前导零。

输出格式

In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).

在唯一的一行中输出佩佳问题的答案。如果所求字符串不存在,则输出 -1(不带引号)。

输入输出样例

  • 输入#1

    047

    输出#1

    4
  • 输入#2

    16

    输出#2

    -1
  • 输入#3

    472747

    输出#3

    7

说明/提示

The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string y either if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that x__i < y__i and for any j (1 ≤ j < i) x__j = y__j. Here |a| denotes the length of string a.

In the first sample three conditions are fulfilled for strings "4", "7" and "47". The lexicographically minimum one is "4".

In the second sample s has no substrings which are lucky numbers.

In the third sample the three conditions are only fulfilled for string "7".

现代编程语言中,字符串的字典序比较由 < 运算符执行。字符串 xx 在字典序上小于字符串 yy,当且仅当以下两个条件之一成立:(1) xx 是 yy 的前缀;或 (2) 存在某个下标 ii(满足 1 ≤ i ≤ min⁡(∣x∣, ∣y∣)1 \le i \le \min(|x|, |y|)),使得 xi < yix_i < y_i,且对任意 jj(满足 1 ≤ j < i1 \le j < i)都有 xj = yjx_j = y_j。其中 ∣a∣|a| 表示字符串 aa 的长度。

在第一个样例中,字符串 "4"、"7" 和 "47" 均满足题目所要求的三个条件。其中字典序最小的是 "4"。

在第二个样例中,字符串 ss 不存在任何是幸运数的子串。

在第三个样例中,仅字符串 "7" 满足题目所要求的三个条件。

输入解题思路,AI测评打分。不知道怎么写?

首页