[Solved] New Administrative Policy with Java, C++, Python

New Administrative Policy: “Pine Tree” is a recently launched startup Event Management company. The company gained a good reputation within a short span because of its highly reliable service delivery. As per the new administrative policies of the company, the Chairman of the company is elected every 4 years, the Finance Director is appointed every 2 years, the Chief Technical Director is elected every 3 years and the Security Chief is replaced every 5 years.

This year, Year X, the newly elected Chairman announced the appointment of the Finance Director, a new Chief Technical Director and congratulated the Security Chief for winning the recent election. That is, all positions were changed over. This is highly unusual. You will quantify how unusual this really is.

Write a program that inputs the year X and the future year Y and lists all years between X and Y inclusive when all positions change.

Input Format:
First line of the input is an integer that corresponds to the year X.
Second line of the input is an integer that corresponds to the future year Y.

Output Format:
Output in separate lines the list of years between X and Y inclusive when all positions change.
Refer sample input and output for formatting specifications.

Sample Input 1:
2004
2100

Sample Output 1:
All positions change in year 2004
All positions change in year 2064

Sample Input 2:
1900
2017

Sample Output 2:
All positions change in year 1900
All positions change in year 1960

Solution

import java.util.*;

class Main {
    public static void main(String[] args) {
        // sauravhathi
        Scanner sc = new Scanner(System.in);
        int cy = Integer.parseInt(sc.nextLine());
        // sauravhathi
        int fy = Integer.parseInt(sc.nextLine());
        int m = 0;
        int t = 0;
        int c = 0;
        int d = 0;
        // sauravhathi
        for (int y = cy; y <= fy; y++) {
            if (m == 0 && t == 0 && c == 0 && d == 0) {
                System.out.println("All positions change in year " + y);
            }
            // sauravhathi
            m = (m + 1) % 4;
            t = (t + 1) % 2;
            c = (c + 1) % 3;
            d = (d + 1) % 5;
        }
        // sauravhathi
    }
}
#include<iostream>
using namespace std;
int main()
{
    int cy,fy,m,t,c,d;
    cin>>cy;
    cin>>fy;
    m=0;
    t=0;
    c=0;
    // sauravhathi
    d=0;
    for(int y=cy;y<=fy;y++)
    {
        if(m==0 && t==0 && c==0 && d==0)
        {
            cout<<"All positions change in year "<<y<<endl;
        }
        // sauravhathi
        m=(m+1)%4;
        t=(t+1)%2;
        c=(c+1)%3;
        d=(d+1)%5;
    }
    return 0;
}
cy = int(input())
fy = int(input())
m = 0
t = 0
c = 0
d = 0
# sauravhathi
for y in range(cy, fy + 1):
    if m == 0 and t == 0 and c == 0 and d == 0:
        print("All positions change in year", y)
        # sauravhathi
    m = (m + 1) % 4
    t = (t + 1) % 2
    c = (c + 1) % 3
    d = (d + 1) % 5

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *