My issue
I can’t figure out why this is giving wrong output.
I created a frequency array which checks frequency of all alphabets present in the string. If freq of any alphabet is 0 than the price of that alphabet gets added to the sum.
My code
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int t; cin>>t ;
while(t--){
char array[26] ;
for(int i = 0 ; i<26 ; i++){
cin>>array[i] ;
}
string str ; cin>>str ;
int freq[26]= {0} ;
for(int i = 0; i<str.length() ; i++){
int temp;
temp = int(str[i]) - 97 ;
freq[temp] ++ ;
}
int sum = 0 ;
for(int i = 0 ; i< 26 ; i++){
if(freq[i] == 0){
sum= sum + array[i] ;
}
}
cout<<sum<<endl ;
}
return 0;
}
Problem Link: MATPAN Problem - CodeChef