import java.util.*;
class letters_0
{
public static void main(String[] args)
{
Scanner ob = new Scanner(System.in);
int t = ob.nextInt();
for(int i = 0; i < t; i++)
{
int a[] = new int[26];
for(int j = 0; j < 26; j++)
a[j] = 0;
int j = 0;
while(ob.hasNextInt())
a[j++] = ob.nextInt();
ob.nextLine();
String s = ob.nextLine();
s = s.toLowerCase();
int h = 0;
for(int k = 0; k < j; k++)
{
int m = 0;
for(int l = 0, n = s.length(); l < n; l++)
{
if((int)s.charAt(l)-96 == a[k])
{
m = 1;
break;
}
}
if(m == 0)
h += a[k];
}
System.out.println(h);
}
}}
i guess you do not the the frequency array concept , see in all these frequencies problems what you need to do is just simply create an array of 26 elements initialized 0.
the simply iterate through the string.
for(i=0;i<s.length();i++)
arr[s[i]-'a']=1;
what this will do is whichever elements are present , for e.g if a is present then 0th pos off arr will be filled with 1 , and then you can just iterate through the array of 26 elements to check which elements are 0 , indicting that they are not present , simply calculate the sum. sum=0
for (int i=0;i<26;i++)
{
if (a[i]==0)
sum+=s[i]
}
print sum
Yes that’s a much better solution to this problem… thanks…
still I am getting the answer from this code… I need to know in which test case am i going wrong?