[Solved] There are 30 days in a given month, numbered from 1 to 30. On Day 1, which is a Monday, the regular 7

There are 30 days in a given month, numbered from 1 to 30. On Day 1, which is a Monday, the regular 7-day workweek is observed (so day 2 is Tuesday, day 3 is Wednesday, and further on).

There is a holiday on Saturday and Sunday. There are N holiday-designated festival days. Be aware that a festival day might fall on a Saturday or Sunday. The festivals’ dates are provided to you. Determine all the holidays that are taking place this month.

Explanation:

Test Case 1: Days 7, 14, 21, 28 are Sundays, whereas days 6, 13, 20, and 27 are Saturdays. Days 5 and 7 are when the festivities take place, however day 7 is already a Sunday. These results in a total of 9 holidays: days 5, 6, 7, 13, 14, 20, 21, and 28.

Test Case 2: The days 6, 13, 20, and 27 fall on Saturdays, whereas the days 7, 14, 21, and 28 fall on Sundays. The festivities take place on day 1, day 6, and day 23. These results in a total of 10 holidays: days 1, 6, 7, 13, 14, 20, 21, 23, and 28.

Input Format:

The number of test cases is indicated by the single integer T on the first line of the input. Following is a description of T test cases.

The number N, which represents the number of festival days, appears on the first line of each test case.

The festival days are indicated by the second line of each test case, which comprises N different, space-separated numbers A1, A2 … AN. Keep in mind that the Ai are not always presented in sorted order.

Sample Input:

3
2
5 7
3
23 1 6
1
13

Constraints:

1 ≤ T ≤ 1000

1 ≤ N ≤ 30

1 ≤ Ai ≤ 30

All the Ai would be distinct.

Output Format:

For every test case, the output must be a new line which determines the total number of holidays.

Sample Output:

9
10
8

Solution

Python

t=int(input())
for i in range(t):
    n=int(input())
    L=list(map(int,input().split()))
    d=8
    lst=[6,13,20,27,7,14,21,28]
    for i in L:

    #sauravhathi
        if i not in lst:
            d=d+1
    print(d)

Java

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

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		
		int tests = in.nextInt();
		
		for (int i = 0; i < tests; i++) {
	        int fDays = in.nextInt(), day, result = 8;
	        
	        Integer[] arr = new Integer[] {6,7,13,14,20,21,27,28};
	        List<Integer> holidays = new ArrayList<>();
	        holidays.addAll(Arrays.asList(arr));
	        //sauravhathi
	        for (int j = 0; j < fDays; j++) {
	            day = in.nextInt();
	            
	            if (!holidays.contains(day)) {
	                result++;
	            }
	        }
	        
	        System.out.println(result);
		}
	}
}

C++

#include <bits/stdc++.h>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--){
		int n, cnt=8;
		cin>>n;
		vector<int> a(n);
		for(int i=0; i<n; ++i){
			cin>>a[i];

             //sauravhathi
			if((a[i])%7!=0 && 7-a[i]%7!=1) cnt++;
		}
		cout<<cnt<<endl;
	}
}

C

#include <stdio.h>

int main(void) {
    int t;
    scanf("%d",&t);
    while(t--){
        int n;
        scanf("%d",&n);
        int count=8;
        int a[n];
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]==6 || a[i]==7 || a[i]==13 || a[i]==14 || a[i]==20 || a[i]==21 || a[i]==27 || a[i]==28)
            count=count;
            else
            count=count+1;
        }
        printf("%d\n",count);
    }
    
	//sauravhathi
	return 0;
}

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 *