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 |
#include <iostream> #include <cstdio> #include <sstream> #include <string> #include <cstring> using namespace std; int arr[27]; int main() { int t,ans; int kase=1; char ch; int R,C,M,N; cin>>t; while(t--) { cin>>R>>C>>M>>N; memset(arr,0,sizeof(arr)); for(int i=0;i<R*C;i++) { cin>>ch; arr[ch-'A']+=1; } int mx=-1; for(int i=0;i<26;i++) { if(arr[i]>mx) mx=arr[i]; } int cnt=0; for(int i=0;i<26;i++) { if(arr[i]==mx) cnt+=1; } ans=mx*cnt*M+(R*C-mx*cnt)*N; cout<<"Case "<<kase++<<": "<<ans<<"\n"; } return 0; } |