Mathison and pangrams Solution Problem Code: MATPAN solution in C, C++, Java, Python and C#

CodeChef Online Judge Solution CodeChef-Beginner Solution

Mathison and pangrams Solution Problem Code: MATPAN solution in C, C++, Java, Python and C#

CodeChef Problem Link Main Link- https://www.codechef.com/problems/MATPAN

Problem Name: Mathison and pangrams Array solution Codechef
Problem Number : CodeChef- Mathison and pangrams Array MATPAN
Online Judge : CodeChef Online Judge Solution
Category: Beginner
Solution Language : C,C plus plus, java, python, c#(c sharp)

CodeChef Online Judge Solution Subsequence Equality Problem Code: LIKECS01 - Solution

CodeChef Solution Mathison and pangrams  Code in C / Codechef MATPAN solution in c language:

#include <stdio.h>
#include <string.h>
#define max 50001

int main()
{
int cost[26],i,t,l,con;
scanf("%d",&t);
while(t--)
{
char str[max];
int a[26]={0};
int sum =0;
for(i=0;i<26;i++)
{
scanf("%d",&cost[i]);
}
scanf("%s",str);
l=strlen(str);
for(i=0;i<l;i++)
{
con=(int)str[i]-97;
a[con]++;
}
for(i=0;i<26;i++)
{
if(a[i]==0)
{
sum=sum+cost[i];
}
}
printf("%dn",sum );
}
return 0;
}

CodeChef Solution Mathison and pangrams Code C++/ CodeChef MATPAN solution in CPP:

#include <iostream>
#include <string>
using namespace std;

int main() {
int t;
cin >> t;
while(t--){
int cost[26];
for(int i=0;i<26;i++)
cin >> cost[i];
string str;
cin >> str;
int freq[26] = {0};
for(int i=0;str[i]!='';i++)
freq[str[i]-97]++;
int total_cost = 0;
for(int i=0;i<26;i++)
if(freq[i]==0)
total_cost += cost[i];
cout << total_cost << endl;
}
return 0;
}

CodeChef Solution Mathison and pangrams Code java/ CodeChef MATPAN solution in Java:

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
MathisonAndPangrams solver = new MathisonAndPangrams();
int testCount = Integer.parseInt(in.next());
for (int i = 1; i <= testCount; i++)
solver.solve(i, in, out);
out.close();
}

static class MathisonAndPangrams {
public void solve(int testNumber, FastReader in, PrintWriter out) {
int[] cost = in.nextIntArray(26);
String s = in.nextString();
long res = 0;
for (int i = 'a'; i <= 'z'; i++) {
res += (s.indexOf((char) (i)) < 0 ? cost[i - 'a'] : 0);
}
out.println(res);
}

}

static class FastReader {
private InputStream stream;
private byte[] buf = new byte[8192];
private int curChar;
private int pnumChars;
private FastReader.SpaceCharFilter filter;

public FastReader(InputStream stream) {
this.stream = stream;
}

private int pread() {
if (pnumChars == -1) {
throw new InputMismatchException();
}
if (curChar >= pnumChars) {
curChar = 0;
try {
pnumChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (pnumChars <= 0) {
return -1;
}
}
return buf[curChar++];
}

public String next() {
return nextString();
}

public int nextInt() {
int c = pread();
while (isSpaceChar(c))
c = pread();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = pread();
}
int res = 0;
do {
if (c == ',') {
c = pread();
}
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = pread();
} while (!isSpaceChar(c));
return res * sgn;
}

public int[] nextIntArray(int n) {
int[] array = new int[n];
for (int i = 0; i < n; i++) {
array[i] = nextInt();
}
return array;
}

public String nextString() {
int c = pread();
while (isSpaceChar(c))
c = pread();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = pread();
} while (!isSpaceChar(c));
return res.toString();
}

private boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}

private static boolean isWhitespace(int c) {
return c == ' ' || c == 'n' || c == 'r' || c == 't' || c == -1;
}

private interface SpaceCharFilter {
public boolean isSpaceChar(int ch);

}

}
}

CodeChef Solution Mathison and pangrams Code / CodeChef MATPAN solution in  Python:

t = input()

for x in range(t):
weights = map(int, raw_input().split())
text = raw_input()

alphabets = 'abcdefghijklmnopqrstuvwxyz'
missing = []
for char in alphabets:
if char not in text:
missing.append(char)

index=[]
for var in missing:
index.append(alphabets.find(var))
ans = 0
for value in index:
ans = ans + weights[value]

print ans

CodeChef Solution Mathison and pangrams Problem Code: MATPAN Code / CodeChef MATPAN solution in  C# (C Sharp):

using System;
using System.Linq;

public class Test
{
public static void Main()
{
// your code goes here
int T = int.Parse(Console.ReadLine());
while (T-- > 0){
var line = Console.ReadLine().Trim().Split().Select(int.Parse).ToArray();
int[] arr = new int[26];
var s = Console.ReadLine();
for (int i = 0; i < s.Length; i++){
arr[(int)(s[i] - 'a')]++;
}
int price = 0;
for (int i = 0; i < 26; i++){
if (arr[i] == 0)
price += line[i];
}
Console.WriteLine(price);
}
}
}

Demonstration:
Just implement this in coding. Since having any problem just put a comment below. Thanks

Tags: CodeChef Online Judge Solution, CodeChef OJ Solution list, CodeChef Problems Solution, CodeChef solver, Codechef all problem solution list, Codechef Mathison and pangrams  code in C, CodeChef MATPAN code in C++, CodeChef Mathison and pangrams solution in C, Codechef solution, CodeChef MATPAN solution in C,CodeChef  MATPAN solution in C++-CPP,CodeChef MATPAN solution in C# (C sharp),CodeChef MATPAN solution in Java,CodeChef MATPAN solution in Python,

Leave a Reply

Your email address will not be published.