Algorithm


Problem Name: beecrowd | 2712

Problem Link: https://www.beecrowd.com.br/judge/en/problems/view/2712

Vehicular Restriction

 

Por , Silva A M BR Brazil

Timelimit: 1

The vehicle restriction of São Paulo city is a restriction on the circulation of motor vehicles in the city. Implemented since 1996 with the aim of improving environmental conditions by reducing the burden of pollutants in the atmosphere, it has consolidated itself as an instrument to reduce congestion in the main highways of the city, during peak times. In the boundary ways, traffic of trucks and automobiles that are within the restriction is not allowed. There is a scale that determines on which days of the week which vehicles can not travel. This scale is governed by the last digit of the vehicle nameplate, being: 

  • Monday, final digit of board 1 and 2 
  • Tuesday, final digit of plate 3 and 4 
  • Wednesday, digit end of plate 5 and 6 
  • Thursday, final digit of plate 7 and 8 
  • Friday, final digit of plate 9 and 0 

The drivers who are caught violating the traffic restriction are charged with a fine and four points in the driver's license.

 

Input

 

The first entry line represents the number of N tests (1 <= N <1000) that should be considered. The other entries are string with maximum size S (1 <= S <= 100) representing each card to be analyzed, so that each card is on a single entry line. The expected format for a valid car plate in São Paulo is "AAA-9999", such that A is a valid character in [A-Z], and 9 is a valid numeric digit in [0-9].

 

Output

 

The set of valid values ​​as output are: MONDAY, TUESDAY, WEDNESDAY, THURSDAY and FRIDAY, according to the predefined constraint table, and FAILURE if the board does not present the defined pattern.

 

 

 

Input Samples Output Samples

3
ABC-1234
XYZ-1010
AAA3333

TUESDAY
FRIDAY
FAILURE

 

Code Examples

#1 Code Example with C Programming

Code - C Programming


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

void check(char str[])
{
    int i, j, len, a=1, b=1, c=1, x;

    len=strlen(str);

    if (len <  8 || len > 8)
        printf("FAILURE\n");

    else
    {
        for (i = 0; i  <  3; ++i)
        {
            if (str[i] >= 'A' && str[i] <= 'Z')
                a=1;
            else
            {
                a=0;
                break;
            }
        }

        if (str[3]!='-')
            b=0;

        for (i = 4; i  <  len; ++i)
        {
            if (str[i] >= '0' && str[i] <= '9')
                c=1;
            else
            {
                c=0;
                break;
            }
        }

        if (a==0 || b==0 || c==0)
            printf("FAILURE\n");

        else
        {
            x=str[len-1]-'0';

            switch (x)
            {
            case 0:
            case 9:
                printf("FRIDAY\n");
                break;

            case 1:
            case 2:
                printf("MONDAY\n");
                break;

            case 3:
            case 4:
                printf("TUESDAY\n");
                break;

            case 5:
            case 6:
                printf("WEDNESDAY\n");
                break;

            case 7:
            case 8:
                printf("THURSDAY\n");
                break;
            }
        }
    }
}

int main(void)
{
    int i, n;
    char str[20];

    scanf("%i", &n);

    for (i = 0; i  <  n; ++i)
    {
        scanf("%s", str);
        check(str);
    }

    return 0;
}

Copy The Code & Try With Live Editor

Input

x
+
cmd
3 ABC-1234 XYZ-1010 AAA3333

Output

x
+
cmd
TUESDAY FRIDAY FAILURE

#2 Code Example with C++ Programming

Code - C++ Programming


#include <iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<math.h>
#include<string>
#include<list>


using namespace std;


#define ll long long
#define input scanf
#define output printf 
#define Loop while
#define echo cout
#define ret return
#define MAX 999999999999999999
#define MIN 0
#define PI 3.1415

vector < bool> a(32);
map<int,string> b;
void si2()
{
	b[1]="MONDAY"; 
    b[2]="MONDAY";
	b[0]="FRIDAY";
	b[9]="FRIDAY";
	b[8]="THURSDAY";
	b[7]="THURSDAY";
	b[5]="WEDNESDAY";
	b[6]="WEDNESDAY";
	b[3]="TUESDAY";
	b[4]="TUESDAY";
}
int main(int argc, char** argv) {
	
	//freopen("c.txt","w",stdout);
	si2();
	int t;
	cin >> t;
	cin.ignore();
	string str;
	while(t--)
	{
		cin >> str;
		if(str.length()==8)
		{
			bool f=false;
			for(int i=0;i < 3; i++>
			{
				if(str[i] >= 65 && str[i] <= 90)
				{
					continue;
				}
				else
				{
					f=true;
					break;
				}
			}
			if(f)cout << "FAILURE\n";
			else
			{
				if(str[3]!='-')
			   {
			     	cout << "FAILURE\n";
			   }
			   else
			   {
			   	f=false;
			   	  for(int i = 4;i  < = 7; i++>
			   	  {
			   	  	if(str[i] < 48 || str[i] > 57)
			   	  	{
			   	  		f=true;
			   	  		break;
					}
				 }
				 if(f)cout << "FAILURE\n";
				 else
				 cout << b[str[7]-48] << endl;
			   }
			}
		}
		else
		{
			printf("FAILURE\n");
		}
	}
	ret 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 ABC-1234 XYZ-1010 AAA3333

Output

x
+
cmd
TUESDAY FRIDAY FAILURE

#3 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;
import java.util.Locale;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.useLocale(Locale.ENGLISH);
		Locale.setDefault(new Locale("en", "US"));
		
		while(sc.hasNext()) {
			int n = Integer.parseInt(sc.nextLine());
			//AAA-9999
			for(int x = 0 ; x  <  n ; x++) {
				String[] s = new String[8];
				String placa = sc.nextLine();
				if (placa.matches("[A-Z]{3}(-)\\d{4}")) {
					s = placa.split("");
					if (s[7].equals("1") || s[7].equals("2")) System.out.println("MONDAY");
					if (s[7].equals("3") || s[7].equals("4")) System.out.println("TUESDAY");
					if (s[7].equals("5") || s[7].equals("6")) System.out.println("WEDNESDAY");
					if (s[7].equals("7") || s[7].equals("8")) System.out.println("THURSDAY");
					if (s[7].equals("9") || s[7].equals("0")) System.out.println("FRIDAY");
				}
				else
					System.out.println("FAILURE");
			}
		}
		sc.close();
	}
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 ABC-1234 XYZ-1010 AAA3333

Output

x
+
cmd
TUESDAY FRIDAY FAILURE

#4 Code Example with Javascript Programming

Code - Javascript Programming


const { readFileSync } = require("node:fs")
const [N, ...input] = readFileSync("/dev/stdin", "utf8").split("\n", 1 + 1e3)

const vehicleLicensePlateFormatValidator = (plate = "") => /^[A-Z]{3}-[0-9]{4}$/.test(plate)

function main() {
	const size = Number.parseInt(N, 10)
	const output = Array.from(
		{ length: size },
		(_, index) => {
			const plate = input[index]
			if (vehicleLicensePlateFormatValidator(plate))
				switch (plate.slice(-1)) {
					case "1": case "2": return "MONDAY"
					case "3": case "4": return "TUESDAY"
					case "5": case "6": return "WEDNESDAY"
					case "7": case "8": return "THURSDAY"
					case "9": case "0": return "FRIDAY"
				}
			else return "FAILURE"
		})

	console.log(output.join("\n"))
}

main()

Copy The Code & Try With Live Editor

Input

x
+
cmd
3 ABC-1234 XYZ-1010 AAA3333

Output

x
+
cmd
TUESDAY FRIDAY FAILURE

#5 Code Example with Python Programming

Code - Python Programming


n = int(input())
while n:
    n -= 1
    placa = input().split('-')
    if (len(placa) == 2) and (len(placa[0]) == 3) and (len(placa[1]) == 4) and (placa[0] == placa[0].upper()):
        try:
            check = int(placa[1])
            r = int(placa[1][3])
            if r > 8 or r == 0:
                print('FRIDAY')
            elif r > 6:
                print('THURSDAY')
            elif r > 4:
                print('WEDNESDAY')
            elif r > 2:
                print('TUESDAY')
            else:
                print('MONDAY')
        except:
            print('FAILURE')
    else:
        print('FAILURE')
Copy The Code & Try With Live Editor

Input

x
+
cmd
3 ABC-1234 XYZ-1010 AAA3333

Output

x
+
cmd
TUESDAY FRIDAY FAILURE
Advertisements

Demonstration


Previous
#2709 Beecrowd Online Judge Solution 2709 The Coins of Robbie Solution in C, C++, Java, Js and Python
Next
#2717 Beecrowd Online Judge Solution 2717 Elf Time Solution in C, C++, Java, Js and Python