**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++.

**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:-**

**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

I see the greatest contents on your blog and I extremely love reading them.

ReplyDeletec++ programming tutorial