Thursday, 14 July 2016

Kangaroo Hacker Rank Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
 
    int x1,x2,v1,v2;
    cin >> x1 >> v1 >> x2 >> v2;
    while(true){
        if(x2 > x1 && v2 > v1 || x1 > x2 && v1 > v2 || v1 == v2){
            cout << "NO" << endl;
            break;
        }
        if((x1 += v1) == (x2 +=v2)){
            cout << "YES" << endl;
            break;
        }
    }
    return 0;
}

Save the Prisoner! Hacker Rank Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
 
    int N,M,S,T;
    cin >> T;
    for(int t = 0; t < T; t++){
        cin >> N >> M >> S;
        if(!((M+S-1)%N))cout << N << endl;
        else cout << (M+S-1)%N << endl;
    }
    return 0;
}

Compare the Triplets Hacker Rank Problem Solution.


Solution:

#include <bits/stdc++.h>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main() {
 
    int a[3],b[3],aPoint = 0,bPoint = 0;
 
    cin >> a[0] >> a[1] >> a[2];
    cin >> b[0] >> b[1] >> b[2];
 
    for(int i = 0; i < 3; i++){
        if(a[i] > b[i])aPoint++;
        else if(a[i] < b[i])bPoint++;
    }
    cout << aPoint << " " << bPoint << endl;
    return 0;
}

Sunday, 3 July 2016

Divisible Sum Pairs Hacker Rank Problem Solution.


Solution:

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

    int n,k,a,cnt = 0;
    vector<int>ar;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> a;
        ar.push_back(a);
    }
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            if((ar[i]+ar[j])%k == 0){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}