0
点赞
收藏
分享

微信扫一扫

【CodeForces - 122B 】Lucky Substring (字符串,水题)

船长_Kevin 2022-06-15 阅读 57

题干:

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 insas 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.

Input

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.

Output

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

Examples

Input

047

Output

4

Input

16

Output

-1

Input

472747

Output

7

Note

The lexicographical comparison of strings is performed by the < operator in the modern programming languages. String x is lexicographically less than string yeither if x is a prefix of y, or exists such i (1 ≤ i ≤ min(|x|, |y|)), that xi < yiand for any j (1 ≤ j < ixj = yj. 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".

题目大意:

   给你一个可能有前导零的数字,让你找一个子串,满足三个条件,其中第三个是,包含最大数量的幸运数字,也就是说,4和7谁多 就要包含谁,又因为是字典序最小的,所以就是那个数字本身喽。

解题报告:

    读懂题目就好了,另外就是注意ifelse啥的之类的别落下情况。先排除-1 的情况,然后再else其他的情况。

   就是题目不太好懂。

AC代码:

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MAX = 1e5 +5;
int main()
{
string s;
cin>>s;
ll len = s.length(),n4=0,n7=0;
for(int i = 0; i<len; i++) {
if(s[i] == '4') n4++;
if(s[i] == '7') n7++;
}
if(n4 == 0 && n7 == 0) puts("-1");
else {
if(n7 > n4) puts("7");
else puts("4");
}
return 0 ;
}

 


举报

相关推荐

0 条评论