All submissions for this problem are available.
Chef 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.
Chef has a positive integer N. He can apply any of the following operations as many times as he want in any order:
- Add 1 to the number N.
- Take some digit of N and replace it by any non-zero digit.
- Add any non-zero leading digit to N.
Find the minimum number of operations that is needed for changing N to the lucky number.
The first line contains a single positive integer T, the number of test cases. T test cases follow. The only line of each test case contains a positive integer N without leading zeros.
For each T test cases print one integer, the minimum number of operations that is needed for changing N to the lucky number.
1 ≤ T ≤ 10
1 ≤ N < 10100000
Input: 3 25 46 99 Output: 2 1 2
|Tags||easy, feb12, witua|
|Time Limit:||1.75 sec|
|Source Limit:||50000 Bytes|
|Languages:||ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.3.2, CPP 6.3, CPP14, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.5, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC|
Fetching successful submissions
If you are still having problems, see a sample solution here.