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

题干:

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.

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 ;} 

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441512.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

*【CodeForces - 122D】Lucky Transformation(字符串问题,思维剪枝,优化,有坑,需注意的问题if的层次总结)

题干&#xff1a; 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. Petya has a number…

c/c++,字符,字符串,各种方式读入与对空格,回车的处理

#include<iostream> #include<string> using namespace std; int main() {char a[50],b[50],charr;//经测试&#xff0c;cin读入字符串&#xff0c;会识别空格和回车为截止&#xff0c;并且不会吞掉&#xff0c;//只是每次读的时候会从第一个不为空格/回车的字符开…

【CodeForces - 357D】Xenia and Hamming (字符串问题,数论,思维)

题干&#xff1a; Xenia is an amateur programmer. Today on the IT lesson she learned about the Hamming distance. The Hamming distance between two strings s  s1s2... sn and t  t1t2... tn of equal length n is value . Record [si ≠ ti] is the Iverson n…

【牛客 - 181D】小叶的巡查(树的直径,数学)

题干&#xff1a; 8102年&#xff0c;牛客系列竞赛空前繁荣。为了更好地管理竞赛&#xff0c;小叶决定巡查于各大城市之间&#xff0c;体察民情。所以&#xff0c;从一个城市马不停蹄地到另一个城市成了小叶最常做的事情。小叶有一个钱袋&#xff0c;用于存放往来城市间的路费…

【蓝桥杯 - 练习】k倍区间(思维,数组)

题干&#xff1a; http://lx.lanqiao.cn/problem.page?gpidT444 问题描述 给定一个长度为N的数列&#xff0c;A1, A2, ... AN&#xff0c;如果其中一段连续的子序列Ai, Ai1, ... Aj(i < j)之和是K的倍数&#xff0c;我们就称这个区间[i, j]是K倍区间。   你能求出数列中…

【 HDU - 1525 】Euclid's Game(较难找规律,玄学博弈,分析必败点必胜点)

题干&#xff1a; Two players, Stan and Ollie, play, starting with two natural numbers. Stan, the first player, subtracts any positive multiple of the lesser of the two numbers from the greater of the two numbers, provided that the resulting number must be…

【CodeForces - 569A】Music (数学公式化简,模拟追及问题)

题干&#xff1a; Little Lesha loves listening to music via his smartphone. But the smartphone doesnt have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk. Unfortunately, internet is not that fast in the city of E…

【CodeForces - 569B】Inventory (标记,乱搞)

题干&#xff1a; Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep …

【CodeForces - 371D】Vessels(思维,元素合并,并查集)

题干&#xff1a; There is a system of n vessels arranged one above the other as shown in the figure below. Assume that the vessels are numbered from 1 to n, in the order from the highest to the lowest, the volume of the i-th vessel is ai liters. Initially…

【UVA - 10891 Game of Sum 】【HRBUST - 1622】 Alice and Bob (区间dp,博弈问题)

题干&#xff1a; 有一个长度为N的整数序列&#xff0c;Alice和Bob轮流取数&#xff0c;Alice先取。每次玩家只能从左端或者右端 取一个或多个数&#xff0c;但不能两端都取。所有数都被取走后游戏结束&#xff0c;然后统计每个人取走的所有数之和&#xff0c; 作为各自的得分…

code iban 是有什么组成_EAN-128码和Code-128码的区别

什么是Code-128码&#xff1f;什么是EAN-128码&#xff1f;二者之间有什么区别&#xff1f;接下来小编就给大家解除心中的疑惑。Code-128码是一种高密度的条形码&#xff0c;可表示从 ASCII 0 到ASCII 127 共128个字符&#xff08;其中包含数字&#xff0c;字母&#xff0c;符号…

计算机中丢失setupxml.dll,Win7电脑安装VideoStudio Pro X6显示丢失SetupXML.dll文件怎么解决...

最近有win7系统用户在电脑安装VideoStudio Pro X6软件的时候&#xff0c;突然出现错误的提示&#xff0c;显示无法启动此程序&#xff0c;因为计算机中丢失SetupXML.dll。尝试重新安装该程序来解决此问题&#xff0c;要怎么办呢&#xff0c;下面给大家讲解一下Win7电脑安装软件…

怎么p出模糊的照片_36. 盲去卷积 - 更加实用的图像去模糊方法

本文同步发表在我的微信公众号和知乎专栏“计算摄影学”&#xff0c;欢迎扫码关注&#xff0c;上一篇文章35. 去卷积&#xff1a;怎么把模糊的图像变清晰&#xff1f;吸引了很多朋友的关注。在这篇文章里面&#xff0c;我给大家讲了一种叫做“非盲去卷积”的方法&#xff0c;当…

【CodeForces - 1038A 】Equality (思维水题,预处理字符串)

题干&#xff1a; You are given a string ss of length nn, which consists only of the first kk letters of the Latin alphabet. All letters in string ss are uppercase. A subsequence of string ss is a string that can be derived from ss by deleting some of its…

docker修改镜像的存储位置_云原生存储详解:容器存储与 K8s 存储卷(内含赠书福利)...

作者 | 阚俊宝 阿里巴巴技术专家参与文末留言互动&#xff0c;即有机会获得赠书福利&#xff01;导读&#xff1a;云原生存储详解系列文章将从云原生存储服务的概念、特点、需求、原理、使用及案例等方面&#xff0c;和大家一起探讨云原生存储技术新的机遇与挑战。本文为该系列…

vb简易计算机器程序,vb简易计算器源码

代码如下&#xff1a;/***Author:乌鸟heart*Version:1.0*/Dim IntX As Double 全局变量&#xff0c;用于存储计算的数值Dim IntOperation As Double 标记运算类型Dim isBegin As Boolean 标记是否已经给IntX赋值Public Sub Clear() 清空命令函数screen.Caption ""En…

【CodeForces - 1038B 】Non-Coprime Partition (构造,数组特征)

题干&#xff1a; Find out if it is possible to partition the first nn positive integers into two non-empty disjoint sets S1S1 and S2S2 such that: gcd(sum(S1),sum(S2))>1gcd(sum(S1),sum(S2))>1 Here sum(S)sum(S) denotes the sum of all elements presen…

计算机专业用锐龙笔记本,轻松应对工作挑战——ThinkPad T14 锐龙版,适合办公的笔记本电脑...

拥有一部适合办公的笔记本电脑&#xff0c;可以成为商务人士忙碌工作中强有力的支持。联想旗下的ThinkPad 系列笔记本电脑&#xff0c;一直秉持为高端商务人士服务的理念&#xff0c;以稳定、流畅、安全的使用体验得到广泛认可。其中的ThinkPad T14 锐龙版&#xff0c;更是有着…

python tabula 使用方法_Python中os.walk()的使用方法

os.walk()主要用来扫描某个指定目录下所包含的子目录和文件。这篇文章将通过几个简单的例子来说明python中os.walk()的使用方法。假设我们的test文件夹有如下的目录结构&#xff1a;我们首先用os.walk扫描test文件夹下所有的子目录和文件&#xff1a;# 使用os.walk扫描目录 imp…

【CodeForces - 1038C】Gambling (博弈问题,优先队列模拟,贪心)

题干&#xff1a; Two players A and B have a list of nn integers each. They both want to maximize the subtraction between their score and their opponents score. In one turn, a player can either add to his score any element from his list (assuming his list…