-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weighted_Uniform_String.java
78 lines (78 loc) · 1.3 KB
/
Weighted_Uniform_String.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
71
72
73
74
75
76
77
78
package rank;
import java.lang.reflect.Array;
import java.util.*;
public class Weighted_Uniform_String
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
String s=sc.next();
long n=sc.nextLong();
long a[]=new long[(int) n];
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
ArrayList<Long> al=new ArrayList<Long>();
long count = 0,k=0,m=0;
for(char c='a';c<='z';c++)
{
for(long i=k;i<s.length();i++)
{
if(c==s.charAt((int) i))
{
count++;
for(int j=0;j<n;j++)
{
if(count==a[j])
{
m=1;
System.out.println("Yes");
break;
}
}
if(1==1)
al.add((count*((int)c-96)));
}
else
{
k=i;
break;
}
}
count=0;
}
System.out.println(al);
Collections.sort(al);
System.out.println(al);
long n1=al.size();
int z=0;
for(int i=0;i<n;i++)
{
long l=0,h=n1-1,m1=(l+h)/2;
while(l<=h)
{
if(a[(int) i]==al.get((int) m))
{
System.out.println("YES");
z=1;
break;
}
else if(a[i]>al.get((int) m))
{
l=m+1;
}
else if(a[i]<al.get((int) m))
{
h=m-1;
}
m=(l+h)/2;
}
if(z==0)
{
System.out.println("NO");
}
z=0;
}
}
}