A8340 | Lucky Substring
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
输出格式
In the only line print the answer to Petya's problem. If the sought string does not exist, print "-1" (without quotes).
输入输出样例
输入 #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".
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".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted