Physical Address

304 North Cardinal St.
Dorchester Center, MA 02124

World Chess Championship CodeChef Solution

Problem – World Chess Championship CodeChef Solution

The World Chess Championship 2022 is about to start. 14 Classical games will be played between Chef and Carlsen in the championship, where each game has one of three outcomes — it can be won by Carlsen, won by Chef, or it can be a draw. The winner of a game gets 2 points, and the loser gets 0 points. If it’s a draw, both players get 1 point each.

The total prize pool of the championship is 100⋅X. At end of the 14 Classical games, if one player has strictly more points than the other, he is declared the champion and gets 60⋅X as his prize money, and the loser gets 40⋅X.

If the total points are tied, then the defending champion Carlsen is declared the winner. However, if this happens, the winner gets only 55⋅X, and the loser gets 45⋅X.

Given the results of all the 14 games, output the prize money that Carlsen receives.

The results are given as a string of length 14 consisting of the characters CN, and D.

  • C denotes a victory by Carlsen.
  • N denotes a victory by Chef.
  • D denotes a draw.

Input Format

  • The first line of input contains an integer T, denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains one integer X, denoting that the total prize pool is 100⋅X.
  • The second line contains the results of the match, as a string of length 14 containing only the characters CN, and D.

Output Format

For each test case, output in a single line the total prize money won by Carlsen.

Constraints

  • 1≤T≤1000
  • 1≤X≤10^6
  • S∣=14
  • S contains only characters DCN.

Subtasks

Subtask #1 (100 points): Original constraints

Sample 1:

Input:
4
100
CCCCCCCCCCCCCC
400
CDCDCDCDCDCDCD
30
DDCCNNDDDCCNND
1
NNDNNDDDNNDNDN
Output:
6000
24000
1650
40

Explanation:

Test case 1: Since Carlsen won all the games, he will be crowned the champion and will get 60⋅X as the prize money which is 60⋅100=6000

Test case 2: Carlsen won 7 games and drew 7, so his score is 2⋅7+1⋅7=21. Chef lost 7 games and drew 7, so his score is 0⋅7+1⋅7=7. Since Carlsen has more points, he will be crowned the champion and will get 60⋅X as the prize money which is 60⋅400=24000

Test case 3: Carlsen and Chef both end up with 14 points. So, Carlsen is declared the winner, but because the points were tied, he receives 55⋅X=55⋅30=1650 in prize money.

World Chess Championship CodeChef Solution in Java

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		int te=in.nextInt();
		while(te-->0){
		    int x=in.nextInt();
		    String s=in.next();
		    int len=s.length();
		    int c=0;
		    int n=0;
		    for(int i=0;i<len;i++){
		        if(s.charAt(i)=='C')
		        c+=2;
		        if(s.charAt(i)=='N')
		        n+=2;
		        if(s.charAt(i)=='D'){
		            c+=1;
		            n+=1;
		        }
		    }
		    if(c>n)
		    System.out.println(60*x);
		    else if(c<n)
		    System.out.println(40*x);
		    else if(c==n)
		    System.out.println(55*x);
		}
	}
}

World Chess Championship CodeChef Solution in Pyth 3

# cook your dish here
t = int(input(""))
for _ in range(t):
    x = int(input(""))
    s = input("")
    if s.count("C") > s.count("N"):
        print(60*x)
    elif s.count("C") < s.count("N"):
        print(40*x)
    else:
        print(55*x)

World Chess Championship CodeChef Solution in C++17

#include <iostream>
using namespace std;

int main() {
int t;
cin>>t;
while(t--){
    int x;
    cin>>x;
    string str;
    cin>>str;
    int count=0;
    int sum=0;
    for(int i=0;i<str.length();i++){
        if(str[i]=='C'){
        count++;
    }
    else if(str[i]=='N'){
        sum++;
}
}
if(count>sum){
    cout<<x*60<<endl;
}
else if(count==sum){
    cout<<x*55<<endl;
}
else{
    cout<<x*40<<endl;
}
}
	return 0;
}
World Chess Championship CodeChef Solution Review:

In our experience, we suggest you solve this World Chess Championship CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the World Chess Championship CodeChef Solution

Find on CodeChef

Conclusion:

I hope this World Chess Championship CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions

Leave a Reply

Your email address will not be published. Required fields are marked *