-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq17.java
More file actions
80 lines (71 loc) · 1.46 KB
/
q17.java
File metadata and controls
80 lines (71 loc) · 1.46 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.util.*;
public class q17 {
public static Hashtable<Integer, Integer> hash;
public static void main(String[] args) {
// TODO Auto-generated method stub
long count = 0;
hash = new Hashtable<Integer, Integer>();
hash.put(0, 0);
hash.put(1, 3);
hash.put(2, 3);
hash.put(3, 5);
hash.put(4, 4);
hash.put(5, 4);
hash.put(6, 3);
hash.put(7, 5);
hash.put(8, 5);
hash.put(9, 4);
hash.put(10, 3);
hash.put(11, 6);
hash.put(12, 6);
hash.put(13, 8);
hash.put(14, 8);
hash.put(15, 7);
hash.put(16, 7);
hash.put(17, 9);
hash.put(18, 8);
hash.put(19, 8);
hash.put(20, 6);
hash.put(30, 6);
hash.put(40, 5);
hash.put(50, 5);
hash.put(60, 5);
hash.put(70, 7);
hash.put(80, 6);
hash.put(90, 6);
hash.put(100, 7);
for(int i = 0; i < 1000; ++i){
count += lettersInNumber(i);
}
System.out.println(count);
}
public static int lettersInNumber(int x){
int result = 0;
if(x >= 100){
int remainder = 0;
int quotient;
remainder = x % 100;
quotient = (x - remainder)/100;
result += hash.get(quotient);
result += hash.get(100);
if(remainder != 0)
result += 3; //and
x = remainder;
}
if(x >= 10){
if(x < 21){
result += hash.get(x);
return result;
}
int remainder = x%10;
int quotient = (x - remainder)/10;
result += hash.get(quotient * 10);
result += hash.get(remainder);
return result;
}
if(x >= 1){
result += hash.get(x);
}
return result;
}
}