Codechef CRED Coins problem solution

In this CRED Coins problem for each bill we pay using the CRED card, we earn some X CRED coins. At a store, each bag is worth 100 CRED coins. a man pays Y number of bills using the CRED card. we need to find the maximum number of begs the man can get from the store.

Let's say for each bill payment, a man can receive 10 CRED coins. man pays 10 bills using CRED. Thus, he receives 100 CRED coins. man can get 1 bag from the store using these coins.

cred coins problem solution

Problem solution in C programming.

#include <stdio.h>

int main(void)
{
    int T;
    scanf("%d", &T);
    for (int i=0; i<T; i++)
    {
        int x,y;
	    scanf("%d %d", &x, &y);
	    int total = x*y;
	    int bags = total/100;
	    printf("%d", bags);
	    printf("\n");
    }
    return 0;
}


Here in the above code first we declare an integer variable T. and then scan the number of test cases.  after that in the for loop, we read the number of bills paid by the man and the number of coins he can get for one bill. and then we count the number of coins he gets by paying the bills. after that, we divide it by 100 to get the number of begs he can get from the store.

Problem solution in C++ programming.

#include <iostream>
using namespace std;

int main() {
    int n,i,z;
    cin>>n;
    int x[n],y[n];
    for( i=0;i<n;i++)
    {
     cin>>x[i]>>y[i];
      z=x[i]*y[i];
      z = z/100;
    cout<<z<<endl;
    
     }
    	return 0;
}


Problem solution in Java programming.

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) 
	{
	    Scanner sc=new Scanner(System.in);
	    int n=sc.nextInt();
	    while(n--!=0){
	    int x=sc.nextInt();
	    int y=sc.nextInt();
	    System.out.println((x*y)/100);
	    }
	        
	    
	}
}


Problem solution in Python programming.

# cook your dish here
t = int(input())
for i in range(t):
    x,y = map(int, input().split())
    z = x*y  
    print (z//100)

Here in the above python code we first read an integer input for the number of test cases. and then in the for loop, we read each input as the number of bills and coins he gets from each bill. after that we first count the number of coins he got after paying his bills. and then we print the number of begs he can get from the coins.

Post a Comment

0 Comments