Time limit per test
2 seconds
Memory limit per test
256 megabytes
Input
Standard Input
Output
Standard output
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 stringS, 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 abve are fulfilled, Petya only needs the lexicographically minimum one. Find this string for Petya.
Input
The single line contains a non-empty stringSWhose length can range from 1 to 50,
Random Sive. 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 ).
Sample test (s) Input
047
Output
4
Input
16
Output
-1
Input
472747
Output
7
Note
The lexicographical comparison of strings is saved med by the <operator in the modern programming ages. StringXIs lexicographically
Less Than stringYEither ifXIs
A prefixY, Or exists suchI(1 digit ≤ DigitILimit ≤ limitMin(|X|, Bytes |Y| )),
ThatXILatency <latencyYIAnd
For anyJ(1 digit ≤ DigitJLatency <latencyI)XJSignature = SignatureYJ.
Here |A| Denotes the length of stringA.
In the first sample three conditions are fulfilled for strings "4", "7"
And "47". The lexicographically minimum one is "4 ".
In the second sampleSHas no substrings which are lucky numbers.
In the third sample the three conditions are only fulfilled for string "7 ".
Description: This question is to find a substring containing lucky numbers 4 or 7, so that the substring appears most frequently in the original string. The simple idea is to count the number of 4 and 7, and output the number that is large. At the same time, because the number of dictionaries is the minimum, when the number of 4 and 7 is the same, output 4. Of course, this question can also be used to produce the substring with the longest output length when the number is equal, for example, 474747. In this case, the output is not 4, but 47, I haven't thought about how to use it for the moment. I may encounter it in the future.
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>using namespace std;int main(){ char a[51];int i,count1,count2;scanf("%s",&a);count1=count2=0;for(i=0;a[i]!='\0';i++){if(a[i]=='4'){count1++;}if(a[i]=='7'){count2++;}}if(count1==0&&count2==0){printf("-1\n");}else if(count1>=count2){printf("4\n");}else if(count1<count2){printf("7\n");}return 0;}