codechef program #31 : Gregorian Calendar ;codechef program #32: Chef and Table Tennis ;codechef program #33:Chef and his Sequence

FLOW015



From now on ,I have decided to post three problems.


Problem Statement #1


According to Gregorian Calendar, it was Monday on the date 01/01/2001. If any year is input,
Write a program to display what is the day on the 1st January of this year.

Input

The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer year.

Output

Display the day on the 1st January of that year in lowercase letter.

Constraints

  •  T  1000
  • 1900 A,B,C 2500

Example

Input

3 
1994
1991
2014

Output

saturday
tuesday
wednesday

My Solution:

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;


public class gregoriancalender {
public static void main(String args[])
{
Scanner in=new Scanner(System.in);
int b=in.nextInt();
while(b-->0)
{
String input_date="01/01/"+in.nextInt();
 SimpleDateFormat format1=new SimpleDateFormat("dd/MM/yyyy");
 Date dt1 = null;
try {
dt1 = format1.parse(input_date);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
 DateFormat format2=new SimpleDateFormat("EEEE");
 String finalDay=format2.format(dt1);
 System.out.println(finalDay.toLowerCase());
}
}

}

Problem Statement #2


Chef likes to play table tennis. He found some statistics of matches which described who won the points in order. A game shall be won by the player first scoring 11 points except in the case when both players have 10 points each, then the game shall be won by the first player subsequently gaining a lead of 2 points. Could you please help the Chef find out who the winner was from the given statistics? (It is guaranteed that statistics represent always a valid, finished match.)

Input

The first line of the input contains an integer T, denoting the number of test cases. The description of T test cases follows. Each test case consist a binary string S, which describes a match. '0' means Chef lose a point, whereas '1' means he won the point.

Output

For each test case, output on a separate line a string describing who won the match. If Chef won then print "WIN" (without quotes), otherwise print "LOSE" (without quotes).

Constraints



  • 1 ≤ T ≤ 1000
  • 1 ≤ length(S) ≤ 100


  • Example

    Input:
    2
    0101111111111
    11100000000000
    
    Output:
    WIN
    LOSE
    

    Explanation

    Example case 1. Chef won the match 11:2, his opponent won just two points, the first and the third of the match.
    Example case 2. Chef lost this match 11:3, however he started very well the match, he won the first three points in a row, but maybe he got tired and after that lost 11 points in a row.

    My Solution:

    import java.util.Scanner;


    public class chefandtennis {
    public static void main(String args[]){
    Scanner in=new Scanner(System.in);
    int a=in.nextInt();
    while(a-->0)
    {
    String input=in.next();
    int len=input.length();
    if(input.charAt(len-1)=='0')
    {
    System.out.println("LOSE");
    }
    else
    {
    System.out.println("WIN");
    }
    }

    Problem Statement #3
    Chef has a sequence of N numbers. He like a sequence better if the sequence contains his favorite sequence as a substring.
    Given the sequence and his favorite sequence(F) check whether the favorite sequence is contained in the sequence

    Input

    The first line will contain the number of test cases and are followed by the cases.
    Each test case consists of four lines: The length of the sequence, the sequence N,the length of F and the sequence F

    Output

    Print "Yes" if the sequence contains the favourite sequence int it otherwise print "No"

    Constraints

    1<=T<=10
    1 1
    Input:
    2
    6
    1 2 3 4 5 6
    3
    2 3 4
    6
    22 5 6 33 1 4
    2
    4 15
    
    
    Output:
    Yes
    No

    My Solution:

    import java.util.Scanner;

    public class chefandhissequence {

    public static void main(String args[]) throws Exception
    {
    Scanner in=new Scanner(System.in);
    int b=in.nextInt();
    for(int i=0;i<b;i++)
    {
    int a=in.nextInt();
    String ab="";
    for(int j=0;j<a;j++)
    {

    ab+=in.nextInt()+" ";
    }

    int cb=in.nextInt();
    String abc="";
    for(int j=0;j<cb;j++)
    {
    abc+=in.nextInt()+" ";
    }
    if(ab.contains(abc))

    System.out.println("Yes");

    else

    System.out.println("No");

    }
    }

    }


    Posted by lol ik

    Comments

    Popular Posts