We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
#include<math.h>#include<stdio.h>#include<string.h>#include<stdlib.h>#include<assert.h>#include<limits.h>#include<stdbool.h>voidsort(char*word){// sortfor(inti=0;i<strlen(word);i++){for(intj=0;j<strlen(word);j++){if(word[i]<word[j]){inttemp=word[j];word[j]=word[i];word[i]=temp;}}}}intmain(){chara;int*h=malloc(sizeof(int)*26),len;for(inth_i=0;h_i<26;h_i++){scanf("%d",&h[h_i]);}char*word=(char*)malloc(512000*sizeof(char));scanf("%s",word);// sortsort(word);// get original lengthlen=strlen(word);// remove duplicateintj=0;for(inti=0;i<strlen(word);i++){if(word[i]!=word[i+1]){word[j++]=word[i];}}word[j]='\0';intmax=0;for(inti=0,temp;i<strlen(word);i++){for(j=0,a=97;j<26;j++,a++){if(word[i]==a){temp=h[j];break;}}if(max<temp)max=temp;// find the largest}printf("%ld",(longint)len*max);return0;}
Designer PDF Viewer
You are viewing a single comment's thread. Return to all comments →
solution in c