Wednesday, 4 October 2017

Hacker Rank solution For Day 26: Nested Logic

Problem:- Write a Hackerrank Solution For Day 26: Nested Logic or Hacker Rank Solution Program In C++ For " Day 26: Nested Logic " or Hackerrank 30 days of code Java Solution:Day 26: Nested Logic solution or Hackerrank solution for 30 Days of Code Challenges or Hackerrank 30 days of code Java Solution, Day 26: Nested Logic solution, or C/C++ Logic & Problem Solving: Day 26: Nested Logic or Hacker Rank Solution For Day 26: Nested Logic.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Explanation:- We have to solve the problem according to given task, the task is given below. There are 4 cases given in the task our solution should pass the all 4 cases according to condition and print the Hackos or fine. Let's take an example and try to find out the solution of this problem.

Task:- Nested Logic Full filled the given task. 
1. If the book is returned on or before the expected return date, no fine will be charged (i.e.: fine = 0).
2. If the book is returned after the expected return day but still within the same calendar month and year as the expected return date, fine = 15 Hackos * (The number of days late).
3. If the book is returned after the expected return month but still within the same calendar year as the expected return date, the fine = 500 Hackos * (The number of days late).
4. If the book is returned after the calendar year in which it was expected, there is a fixed fine of 10000 Hackos

Example:- Suppose we have given below input. Input formate is first DD: MM: YYYY

Actual  =====>15 12 2015
Expected ===>15 6 2015

Now according for our logic in the program.

diff =    15 - 15 = 0.
mdiff = 12 - 6 = 6. 
ydiff =  2015 - 2015 = 0.

Now first condition is failed actual year - expected year so according to ternary operator second part will be executed, so according to second part (Month-Month1>0&&ydiff==0) this part is passed cause 12 - 6 = 6 and year difference(actual year - expected ) is 0 so Month difference ((actual year - expected) * 500). Month difference is 6 * 500 = 3000. So this is a Hackos we have to pay.

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- If this post is beneficial for you and you want Updates for New post then please like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.


Tip:- Copy the colored code or full code(According to Requirement) and paste it into hacker rank editor.All solution provided here are in C++ (CPP) if any reader wants these solutions in C, and Java comments below or Email me with your query like " day n solution in C / C++ / Java. Check the end of the post solutions with the full explanation

Submit Your Solution Here:- Click Here

Solution:-

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

int main() 
{
    int Day, Month, Year, Day1, Month1, Year1, mdiff, ddiff, ydiff, diff;
    
    cin>>Day>>Month>>Year>>Day1>>Month1>>Year1;

    mdiff = Month - Month1;
    ddiff = Day - Day1;
    ydiff = Year - Year1;
    diff=(Year-Year1>0)?10000:(Month-Month1>0&&ydiff==0)?mdiff*500:(Day-Day1>0 && ydiff==0)?ddiff*15:0;    
    cout<<diff<<endl;

    return 0;
}

Output:-


Hacker Rank solution For Day 26: Nested Logic

You May Also Like:-


1. Hackerrank Solution For Day 20: Sorting

2. Hackerrank Solution For Day 21: Generics

3. Hackerrank Solution For Day 22: Binary Search Trees

4. Hackerrank Solution For Day 23: BST Level-Order Traversal

5. Hackerrank Solution For Day 24: More Linked Lists

6. Hackerrank Solution For Day 25: Running Time and Complexity

7. Hackerrank Solution For Day 26: Nested Logic

8. Hackerrank Solution For Day 27: Testing

9. Hackerrank Solution For Day 28: RegEx, Patterns, and Intro to Databases

10. Hackerrank Solution For Day 29: Bitwise AND


Ghanendra Yadav
Ghanendra Yadav

I Am Ghanendra Yadav Owner Of This Website. I Love Programming, Web Developing, Logo Making, Banner And Website designing. Currently I Am Studying In NIT Warangal And Also Working With WSDC( As Web Application Developer ) In NIT Warangal For Any Query Mail Me I Will Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment