LUCKY5 - Editorial

PROBLEM LINKS

Practice
Contest

DIFFICULTY

EASY

EXPLANATION

In this problem the only thing you should notice is that the only operation that you need to use is the changing of digits.

Indeed, adding leading digit operation worsens our situation - it gives nothing good.
On the other hand, incrementing number by 1 is equivalent to changing of last digit except the case when the last digit is 9. If N has k trailing nines and d < 9 is the next digit after nines then the block d 9 9 … 9 9 will be changed to (d+1) 0 0 … 0 0. So it is equivalent to changing of digit d and some useless changes from 9 to 0 that do not involve lucky digits. So we can use just one change of digit instead of this incrementing operation with the same effect in sense of lucky digits.
After noticing this, we see that the answer to the problem is simply the number of unlucky digits of N.

SETTER’S SOLUTION

Can be found here.

TESTER’S SOLUTION

Can be found here.

This is incorrect.
Suppose N = 539, add leading digit operation gives 544, then change 5 to 4 => total number of operations is 2 while number of unlucky digits is 3.

‘Add leading digit’ means write some digit at the beginning of the number like: 539 -> 4539.

I think u havenot got the point adding 1 to 539 means total of operations as 1 add + change of two digits on adding and further we have to change units place afterwards…

What is wrong in my solution?
Instead of using a String, I took character by character input.
Please have a look http://www.codechef.com/viewsolution/4928966

what if none of the input digit is 4 or 7 and length of input is 10^100000 ? In that case 10^10000 will be the answer .

Hello priyankpalod,you can check out this solution check if still problem persists.

question statement has dual meaning…add any leading digits to number

what is the error in my code

for _ in range(int(input())):

x=input()

a=x.count(‘4’)+x.count(‘7’)

print(int(len(x)-a))