Posts

Search

L1 - Mathematical Skills01

Assume you are given a square matrix of dimension N. Let this matrix be called A.
Your task is to rotate A in clockwise direction by S degrees, where S is angle of rotation.

On the matrix, there will be 3 types of operations viz.

Rotation
Rotate the matrix A by angle S, presented as input in form of A S

Querying
Query the element at row K and column L, presented as input in form of Q K L

Updation
Update the element at row X and column Y with value Z, presented as input in form of U X Y Z
Print the output of individual operations as depicted in Output Specification

Input Format

Input will consist of three parts, viz.
1. Size of the matrix (N)
2. The matrix itself (A = N * N)
3. Various operations on the matrix, one operation on each line. (Beginning either with A, Q or U)

-1 will represent end of input.

Note:
Angle of rotation will always be multiples of 90 degrees only.
All Update operations happen only on the initial matrix. After update all the previous rotations have to be applied on the updated matrix

Constraints

1<=N<=1000
1<=Aij<=1000
0<=S<=160000
1<=K, L<=N
1<=Q<=100000

Output Format

For each Query operation print the element present at K-L location of the matrix in its current state.

Sample Input 0

2
1 2
3 4
A 90
Q 1 1
Q 1 2
A 90
Q 1 1
U 1 1 6
Q 2 2
-1

Sample Output 0

3
1
4
6
 
Explanation 0

Initial Matrix
1 2
3 4

After 90 degree rotation, the matrix will become
3 1
4 2
Now the element at A11 is 3 and A12 is 1.

Again the angle of rotation is 90 degree, now after the rotation the matrix will become
4 3
2 1
Now the element at A11 is 4.

As the next operation is Update, update initial matrix i.e.
6 2
3 4

After updating, apply all the previous rotations (i.e. 180 = two 90 degree rotations).
The matrix will now become
4 3
2 6
Now A22 is 6.

Solution :
 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    int n;
    scanf("%d",&n);
    int a[n][n],i,j,s=0;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
            scanf("%d",&a[i][j]);
    }
    while(1)
    {
        char c;
        scanf(" %c",&c);
        if(c == '-')
            return 0;
        else if(c=='A')
        {
            int x;
            scanf("%d",&x);
            s=s+x/90;
            s=s%4;
        }
        else if(c == 'Q')
        {
            int x,y;
            scanf("%d%d",&x,&y);
            x--;
            y--;
            if(s == 0)  printf("%d\n",a[x][y]);
            if(s== 1) printf("%d\n",a[n-y-1][x]);
            if(s== 2) printf("%d\n",a[n-x-1][n-y-1]);
            if(s== 3) printf("%d\n",a[y][n-x-1]);
        }
        else if(c == 'U')
        {
            int x,y,z;
            scanf("%d%d%d",&x,&y,&z);
            a[x-1][y-1]=z;
        }
    }
    return 0;
}

Are they Pangrams

A string is a pangram if it contains all letters of the English alphabet, ascii['a'-'z']. Given a list of strings, determine if each one is a pangram or not. Return "1" if true and "0" if false.

Example

pangram = ['pack my box with five dozen liquor jugs', 'this is not a pangram']
the string 'pack my box with five dozen liquor jugs' is a pangram , because it contains all the letters 'a' through 'z' the string 'this is not a pangram' is not a pangram.Assemble a string of the two results, in order.  The result is '10'.
Function Description Complete the function isPangram n the editor below.

isPangram has the following parameter(s):
    string pangram[n]:  an array of strings
Returns:  
    string: a string where each position represents the results of a test. Use '1' for true and '0' for false.

Constraints

1 ≤ n ≤ 100
Each string pangram[i] (where 0 ≤ i < n) is composed of lowercase letters and spaces.
1 ≤ length of pangram[i] ≤ 105
 
Input Format for Custom Testing

Input from stdin will be processed as follows and passed to the function.
The first line contains an integer n, the size of the array pangram.The next n lines each contain an element, pangram[i], where 0 ≤ i < n.

Sample Case 0
Sample Input 0

STDIN                                                                                Function Parameters 
-----                                                                                            ------------------- 
4                                                                                             →  pangram[] size n = 4 
we promptly judged antique ivory buckles for the next prize   →  pangram[] = ["we promptly judged antique ivory buckles for the next prize",
we promptly judged antique ivory buckles for the prizes                 "we promptly judged antique ivory buckles for the prizes",
the quick brown fox jumps over the lazy dog                                   "the quick brown fox jumps over the lazy dog", 
the quick brown fox jump over the lazy dog                                    "the quick brown fox jump over the lazy dog" ]

Sample Output 0

1010

Explanation 0

pangram[0] = True
pangram[1] = False
pangram[2] = True
pangram[3] = False
The strings pangram[0] and pangram[2] are pangrams, and the others are not.
The result is '1010'
Sample Case 1Sample Input 1
STDIN                                                                       Function Parameters
-----                                                                       -------------------
4                                                                         → pangram[] Size n = 4 
cfchcfcvpalpqxenhbytcwazpxtthjumliiobcznbefnofyjfsrwfecxcbmoafes tnulqkvx
oxhctvhybtikkgeptqulzukfmmavacshugpouxoliggcomykdnfayayqutgwivwldrkp
gpecfrak zzaxrigltstcrdyhelhz rasrzibduaq  cnpuommogatqem
hbybsegucruhxkebrvmrmwhweirx mbkluwhfapjtga liiylfphmzkq
 
Sample Output 1

0000

Explanation 1

pangram[0] = False
pangram[1] = False
pangram[2] = False
pangram[3] = False
No string is a pangram.
The result is '0000'

Solution:

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.function.*;
import java.util.regex.*;
import java.util.stream.*;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;


import java.util.*;
class Result {

    /*
     * Complete the 'isPangram' function below.
     *
     * The function is expected to return a STRING.
     * The function accepts STRING_ARRAY pangram as parameter.
     */
      public static boolean checkPangram(String str) 
    { 
        boolean[] mark = new boolean[26]; 
  int index = 0
        for (int i = 0; i < str.length(); i++) { 
            if ('A' <= str.charAt(i) && str.charAt(i) <= 'Z'
                index = str.charAt(i) - 'A'
            else if ('a' <= str.charAt(i) && str.charAt(i) <= 'z'
  
                index = str.charAt(i) - 'a'
            else
                continue
            mark[index] = true
        } 
        for (int i = 0; i <= 25; i++) 
            if (mark[i] == false
                return (false); 
        return (true); 
    } 

    public static String isPangram(List<String> pangram) {
    String ar[]=new String [pangram.size()];
    int j=0;
    for (String str : pangram) 
    {
        ar[j]=str;
        System.out.println(ar[j]);
        j++;
    }
    String str1="";
    for(int k=0; k<pangram.size();k++)
    {
        String str=ar[k];
        if (checkPangram(str) == true
        str1=str1+"1";
        else
        str1=str1+"0";
    }
    return str1;
    }

}

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv("OUTPUT_PATH")));

        int pangramCount = Integer.parseInt(bufferedReader.readLine().trim());

        List<String> pangram = IntStream.range(0, pangramCount).mapToObj(i -> {
            try {
                return bufferedReader.readLine();
            } catch (IOException ex) {
                throw new RuntimeException(ex);
            }
        })
            .collect(toList());

        String result = Result.isPangram(pangram);

        bufferedWriter.write(result);
        bufferedWriter.newLine();

        bufferedReader.close();
        bufferedWriter.close();
    }
}