In this HackerRank Day 26 Nested Logic 30 days of code problem set, we need to develop a program that can accept a line of integers separated with space. and now we need to print the day month and year using these integers on the output screen.


HackerRank Day 26 Nested Logic 30 days of code solution


Problem solution in Python 2 programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
[da, ma, ya] = [int(x) for x in raw_input().strip().split(" ")]
[de, me, ye] = [int(x) for x in raw_input().strip().split(" ")]
if ya > ye:
    print 10000
elif ma > me:
    print 500 * (ma - me)
elif da > de:
    print 15 * (da - de)
else:
    print 0


Problem solution in Python 3 programming.

n = input()
x = list(map(int, n.split()))
m = input()
y = list(map(int, m.split()))
z=0
if y[2] < x[2]:
    z = 10000
elif y[2] == x[2]:
    if y[1] < x[1]:
        z = 500*(x[1]-y[1])
    elif y[0] < x[0]:
        z = 15*(x[0]-y[0])

print(z)


Problem solution in java programming.

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

public class Solution {

    public static void main(String[] args) {
        int fine;
        
        Scanner scan = new Scanner(System.in);
        
        int returnDay = scan.nextInt();
        int returnMonth = scan.nextInt();
        int returnYear = scan.nextInt();
        
        int dueDay = scan.nextInt();
        int dueMonth = scan.nextInt();
        int dueYear = scan.nextInt();
        
        scan.close();
        
        if(returnYear <= dueYear){
            if(returnMonth <= dueMonth){
                if(returnDay <= dueDay){
                    fine = 0;
                }else{
                    fine = (returnDay - dueDay) * 15;
                }
            }else{
                fine = (returnMonth - dueMonth) * 500;
            }
        }else{
            fine = 10000;
        }
        
        System.out.println(fine);
    }
}


Problem solution in c++ programming.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int d1;
    int m1;
    int y1;
    cin >> d1 >> m1 >> y1;
    int d2;
    int m2;
    int y2;
    cin >> d2 >> m2 >> y2;
    
    if(y1 < y2 || (y1 == y2 && m1 < m2) || (y1 == y2 && m1 == m2 && d1 <= d2)){
        cout << 0 << endl;
    }
    else if(m1 == m2 && y1 == y2){
        cout << 15*(d1 - d2) << endl;
    }
    else if(y1 == y2){
        cout << 500*(m1 - m2) << endl;
    }
    else {
        cout << 10000*(y1 - y2) << endl;
    }

    return 0;
}


Problem solution in c programming.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int main() {
    int returned[3] = {0};
    int expected[3] = {0};
    
    scanf("%d %d %d\n", &returned[0], &returned[1], &returned[2]);
    scanf("%d %d %d\n", &expected[0], &expected[1], &expected[2]);
    
    if(returned[2] > expected[2]) {
        printf("10000\n");
    } else if (returned[1] > expected[1]) {
        int months_late = returned[1] - expected[1];
        printf("%d\n", months_late * 500);
    } else if (returned[0] > expected[0]) {
        int days_late = returned[0] - expected[0];
        printf("%d\n", days_late * 15);
    } else {
        printf("0\n");
    }
    
    return 0;
}


Problem solution in Javascript programming.

function processData(input) {
    //Enter your code here
    var inputArr = input.split('\n'),
        actual = inputArr[0].split(' '),
        expected = inputArr[1].split(' '),
        month = 1,
        day = 0,
        year = 2,
        fine = 0;
        
    if (actual[year] > expected[year]) {
        fine = 10000;
    } else if (actual[month] > expected[month]) {
        fine = 500 * (actual[month] - expected[month]);
    } else if (actual[day] > expected[day]) {
        fine = 15 * (actual[day] - expected[day]);
    }
    
    console.log(fine);
} 

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});