122B - Lucky Substring - CodeForces Solution


brute force implementation *1000

Please click on ads to support us..

Python Code:

n=input()
a=-1
f=n.count('4')
s=n.count('7')
if f>0:
    a=4
if s>f:
    a=7
print(a)

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    string s;
    cin>>s;
    int totalSeven = 0,totalFour = 0,i;
    for(i=0; s[i]; i++)
    {
        if(s[i]=='4')
            totalFour++;
        else if(s[i]=='7')
            totalSeven++;
    }
    if(!totalFour && !totalSeven)
        cout<<-1<<endl;
    else if(totalFour>=totalSeven)
        cout<<4<<endl;
    else
        cout<<7<<endl;
}
 


Comments

Submit
0 Comments
More Questions

678A - Johny Likes Numbers
1699C - The Third Problem
1697D - Guess The String
754B - Ilya and tic-tac-toe game
760A - Petr and a calendar
1573A - Countdown
166A - Rank List
1631B - Fun with Even Subarrays
727A - Transformation from A to B
822B - Crossword solving
1623A - Robot Cleaner
884B - Japanese Crosswords Strike Back
862B - Mahmoud and Ehab and the bipartiteness
429A - Xor-tree
1675C - Detective Task
950A - Left-handers Right-handers and Ambidexters
672B - Different is Good
1C - Ancient Berland Circus
721A - One-dimensional Japanese Crossword
1715B - Beautiful Array
60B - Serial Time
453A - Little Pony and Expected Maximum
1715A - Crossmarket
1715C - Monoblock
1512C - A-B Palindrome
1679B - Stone Age Problem
402A - Nuts
792A - New Bus Route
221A - Little Elephant and Function
492C - Vanya and Exams