-
Notifications
You must be signed in to change notification settings - Fork 161
/
weight.java
70 lines (58 loc) · 1.19 KB
/
weight.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.util.*;
public class weight
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
LinkedList<String> list=new LinkedList<String>();
LinkedList<Integer> list3=new LinkedList<Integer>();
String s=sc.nextLine().toUpperCase();
int sum=0;
int n=sc.nextInt();
for(int j=0;j<n;j++)
list3.add(sc.nextInt());
LinkedList<String> list2=new LinkedList<String>();
for(int i=65;i<=90;i++)
{
list.add(Character.toString((char)i));
}
for(int i=0;i<s.length();i++)
{
list2.add(Character.toString(s.charAt(i)));
}
LinkedList<Integer> summ=new LinkedList<Integer>();
LinkedList<Integer> l2=new LinkedList<Integer>();
//System.out.println(set);
int c=0,p=0;
try{
Iterator itr=list2.iterator();
while(itr.hasNext()){
sum=0;
sum+=(list.indexOf(itr.next())+1);
summ.add(sum);
}
//list2.clear();
for(int itr1:summ)
{
c=itr1;
if(l2.contains(c)==true)
p+=itr1;
else
p=c;
l2.add(p);
}
}
catch(Exception e)
{}
finally
{
Collections.sort(l2);
for(int k:list3)
{
if(Collections.binarySearch(l2,k)>=0)
System.out.println("Yes");
else
System.out.println("No");
}
}
}
}