-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLuckyPurchase.java
More file actions
51 lines (45 loc) · 985 Bytes
/
LuckyPurchase.java
File metadata and controls
51 lines (45 loc) · 985 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class LuckyPurchase {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int t = in.nextInt();
String s1="";
int n1=Integer.MAX_VALUE;
for(int a0 = 0; a0 < t; a0++)
{
String s = in.next();
int n = in.nextInt();
if(equal7and4(n)&&n<n1)
{
s1=s;
n1=n;
}
}
if(n1==Integer.MAX_VALUE)
System.out.println("-1");
else System.out.println(s1);
in.close();
}
private static boolean equal7and4(int n)
{
int count=0,r;
while(n!=0)
{
r=n%10;
if(r==7)
count++;
else if(r==4)
count--;
else return false;
n=n/10;
}
if(count==0)
return true;
else return false;
}
}