Saturday, 14 March 2015

Calculate The Statistics Of Players in C Solution

/*   Since 2001, Bangladesh captain Mashrafe Mortaza has been a staple of Bangladesh’s pace attack. The BCC (Bangladesh Cricket Council) wants to compute certain statistics about him which are:
AVE (Bowling average: The average number of runs conceded per wicket) ECON (Economy rate: The average number of runs conceded per over) SR (Strike rate: The average number of balls bowled per wicket taken) Now, write a C program which can help BCC to calculate the statistics of players like Mashrafe. You need to take appropriate input from user to compute AVE, ECON & SR. */


Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int NumOfBallsBowled,NumOfRunsConceded,NumOfWickTaken;
    float BowlingAverage,EconomyRate,StrikeRate;

    /*User input*/
    printf("Number of balls bowled: ");
    scanf("%d",&NumOfBallsBowled);
    printf("Number of runs conceded: ");
    scanf("%d",&NumOfRunsConceded);
    printf("Number of wickets taken: ");
    scanf("%d",&NumOfWickTaken);

    /*Calculating Average*/
    BowlingAverage = (float)(NumOfRunsConceded/NumOfWickTaken);
    EconomyRate = (float)((NumOfRunsConceded)/(NumOfBallsBowled/6));//here Type casting(float) converting a variable from one data type to
    StrikeRate = (float)(NumOfBallsBowled/NumOfWickTaken);          // another data type.

    /*Printing Calculated value*/
    printf("\nBowling Average: %.2f\n",BowlingAverage);
    printf("Economy Rate: %.2f\n",EconomyRate);//If you want the output to contain a different number of
    printf("Strike Rate: %.2f\n",StrikeRate);  //decmal places then you must put a decimal point between % and f
    return 0;
}

Monday, 2 March 2015

Uva-10038 - Jolly Jumpers Solution

/*Uva-10038 - Jolly Jumpers Solution*/

Solution:

#include<bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int ar[3500],ar2[3500],n;
    while(cin >> n){
        for(int i = 0; i < n; i++)cin >> ar[i];
        int k = 1;
        for(int i = 1; i < n;i++){
            ar2[k++] = abs(ar[i]-ar[i-1]);
        }
        sort(ar2+1,ar2+k);
        bool ok = true;
        for(int i = 1; i < k; i++){
            if(ar2[i] != i){
                ok = false;
                break;
            }
        }
        if(ok)cout << "Jolly" << endl;
        else cout << "Not jolly" << endl;
    }
    return 0;
}

Uva-12149 - Feynman Solution

/*Uva-12149 - Feynman Solution */

Solution:

#include<bits/stdc++.h>
using namespace std;
int ar[110];
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    ar[1] = 1;
    for(int i = 2; i < 101; i++)ar[i] = (i*i)+ar[i-1];
    int n;
    while(cin >> n && n){
        cout << ar[n] << endl;
    }
    return 0;
}

Uva-12554 - A Special Happy Birthday Song solution

/*Uva-12554 - A Special Happy Birthday Song Solution*/

Solution:

#include<bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    string name[110],song[] = {"Happy","birthday","to","you","Happy","birthday","to","you","Happy","birthday","to","Rujia","Happy","birthday","to","you"};
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> name[i];
    }
    int j = 0,k = 0,m = 1;
    if(n > 16)m = ceil(n/16)+1;
    for(int i = 0; i < m*16; i++,j++,k++){
        if(k == 16)k = 0;
        if(j == n)j = 0;
        cout << name[j] << ": " << song[k] << endl;
    }
    return 0;
}