-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathTwoTwo.java
56 lines (51 loc) · 1.24 KB
/
TwoTwo.java
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
import java.io.*;
import java.util.*;
public class Solution {
static Map<String, Boolean> map;
static {
String s = "1";
int max = 800;
map = new HashMap<>();
map.put("1", true);
for(int i=0;i<max;i++){
s = multiplyWith2(s);
// System.out.println(s);
map.put(s, true);
}
}
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
StringBuilder ans = new StringBuilder();
while(t--!=0){
String str = br.readLine();
char c[] = str.toCharArray();
int l = c.length;
String num;
int count = 0;
for(int i=0;i<l;i++){
if(c[i] == '0') continue;
for(int j=i+1;j<=l;j++){
num = str.substring(i, j);
if(map.containsKey(num)) count++;
// System.out.println(i + " - " + j + " : " + count);
}
}
ans.append(count + "\n");
// System.out.println(count);
}
System.out.println(ans.toString());
}
static String multiplyWith2(String s){
int l = s.length();
int sum = 0, carry = 0;
String ans = "";
for(int i=l-1;i>=0;i--){
sum = carry + (s.charAt(i) - '0')*2;
carry = sum/10;
ans = (sum%10) + ans;
}
if(carry!=0) ans = carry + ans;
return ans;
}
}