-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSimilar_Char.java
52 lines (40 loc) · 1.04 KB
/
Similar_Char.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
import java.util.Scanner;
public class Similar_Char
{
public static void main(String[] args)
{
String tempu1=new String("");
int co1[];
Scanner in=new Scanner(System.in);
int pu1[];
int n,qu1,i;
n=in.nextInt();
in.nextLine();
String s=in.nextLine();
qu1=in.nextInt();
pu1=new int[qu1];
co1=new int[qu1];
for(i=0;i<qu1;i++)
{
pu1[i]=in.nextInt();
}
for(i=0;i<qu1;i++)
{
tempu1=s.substring(0,(pu1[i]-1));
char ca=s.charAt(pu1[i]-1);
for(int j=0;j<tempu1.length();j++)
{
char ch=tempu1.charAt(j);
if(ch==ca)
{
co1[i]++;
}
}
}
for(i=0;i<qu1-1;i++)
{
System.out.println(co1[i]+" ");
}
System.out.print(co1[i]);
}
}