Designer PDF Viewer - HackerRank || HackerRank Designer PDF Viewer Solution

Problem Name: Designer PDF Viewer
Judge: HackerRank
Problem link: Designer PDF Viewer



HackerRank Designer PDF Viewer Solution in C

#include <stdio.h>

int main()
{
    int ar[26];
    int i, max = 0, length = 0, y;
    for (i = 0; i < 26; i++) scanf("%d", &ar[i]);
    char ch[11];
    for (i = 0; i < 11; i++)
    {
        ch[i] = getchar();
        y = ch[i] - 97;
        if (ar[y] > max) max = ar[y];
    }
    for (i = 0; i < 11; i++)
    {
        if(ch[i] >= 97 && ch[i] <= 122) length = length + 1;
    }
    printf("%d\n", max * length);
    return 0;
}


HackerRank Designer PDF Viewer Solution in C++/Cpp

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int alphabets[26], max = 0;
    for (int i = 0; i < 26; i++) cin >> alphabets[i];
    string word;
    cin >> word;
    int value[word.length()];
    for (int i = 0; i < word.length(); i++)
    {
        value[i] = word[i] - 97;
        if (alphabets[value[i]] > max) max = alphabets[value[i]];
    }
    cout << max * word.length() << endl;
    return 0;
}


HackerRank Designer PDF Viewer Solution in Java

import java.util.Scanner;

public class Designer_PDF_Viewer {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int[] alphabets = new int[26];
        for (int i = 0; i < 26; i++) alphabets[i] = input.nextInt();
        String word = input.next();
        int max = 0;
        int[] position = new int[word.length()];
        for (int i = 0; i < word.length(); i++) {
            position[i] = word.charAt(i) - 97;
            if (alphabets[position[i]] > max) max = alphabets[position[i]];
        }
        System.out.println(max * word.length());
    }
}




Next Post Previous Post
No Comment
Add Comment
comment url