Lucky digits

Practice

Author: Anurag
Tester: Anurag
Editorialist: Anurag

DIFFICULTY:

EASY,MEDIUM,GREEDY,STRING,CAKEWALK, SIMPLE

PREREQUISITES:

Math ,String

PROBLEM:

Motu loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 5 and 9. For example, numbers 59875959, 4 are lucky and 33256 is not lucky

because count of lucky digit must be greater then count of unlucky digits .

EXPLANATION:

Motu has given a string of numbers S in that string some digits are motu’s favourite digits these digits were name as lucky digits that is 5 and 9
suppose in any string count of lucky digit is greater then the count of unlucky digit then the given string is lucky otherwise unlucky

for example

54593

In above case number of lucky digits are 3 and number of unlucky digit is 2 there for output is LUCKY .

SOLUTIONS:

Setter's Solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void testcase()
{
ll n,m,count=0;
cin>>n;
string str;
str=to_string(n);
m=str.size();
// cout<<str;
// cout<<(str[1]+1);
for(int i=0;i<m;i++){
if(str[i]==‘5’ || str[i]==‘9’){
count++;
}
}
//cout<<endl;
// cout<<count<<" ";
if(count>(m/2)){
cout<<“LUCKY”;
}
else{
cout<<“UNLUCKY”;
}

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Tester's Solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void testcase()
{
ll n,m,count=0;
cin>>n;
string str;
str=to_string(n);
m=str.size();
// cout<<str;
// cout<<(str[1]+1);
for(int i=0;i<m;i++){
if(str[i]==‘5’ || str[i]==‘9’){
count++;
}
}
//cout<<endl;
// cout<<count<<" ";
if(count>(m/2)){
cout<<“LUCKY”;
}
else{
cout<<“UNLUCKY”;
}

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}

Editorialist's Solution

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
void testcase()
{
ll n,m,count=0;
cin>>n;
string str;
str=to_string(n);
m=str.size();
// cout<<str;
// cout<<(str[1]+1);
for(int i=0;i<m;i++){
if(str[i]==‘5’ || str[i]==‘9’){
count++;
}
}
//cout<<endl;
// cout<<count<<" ";
if(count>(m/2)){
cout<<“LUCKY”;
}
else{
cout<<“UNLUCKY”;
}

}
int main()
{
int t;
cin>>t;
while(t–)
{
testcase();
cout<<endl;
}
return 0;
}