BITFRENZY

a blog dedicated to technology and programming to shape nation's future.

Breaking

Post Top Ad

Wednesday, May 15, 2019

designer PDF viewer hackerrank solution in C language

#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<math.h>
#include<string.h>
int main()
{
int h[26];
for(int i=0;i<26;i++)
{
scanf("%d",&h[i]);
}
char*word=(char*)malloc(512000*sizeof(char));
scanf("%s",word);
int len=strlen(word);
int t=h[word[0]-97];
for(int i=1;i<len;i++)
{
if(t<h[word[i]-97])
t=h[word[i]-97];
}
printf("%d",(t*len));
return 0;
}


2 comments:

  1. why are we allocating the space dynamically for the word?

    ReplyDelete
  2. can't we use " s[11]; gets(s); " to take string instead of calloc??

    ReplyDelete

Post Top Ad

Your Ad Spot

Pages