Menu
Topics Index
...
`

Weekend Hack - 2 - 19 Jan 2013 - Rs. 150 has these questions


Find all the pawns which a camel can kill

In chess, assuming that the columns are numbered A to H and the rows are numbered 1 to 8. Write a program to find all the pawns which the camel can kill. Assume that there are only the given pawns on the chess board.
NOTE: The list returned should be first sorted by columns and then by rows, so A4 comes before B1 and C7 comes before D5 etc.,
Input (Position, List Of Positions) Output (Sorted List of Positions)
Camel = C1 pawns = [A3, B2, B1, H6, D3, E3, G3, E2] [A3, B2, E3, H6]
Camel = G1 pawns = [H1, C5, A8, D4, F1, E1, H2] [C5, D4, F1, H2]
Camel = D5 pawns = [A5, B7, C8, C6, A2, B3, H1, G4, F7, D6] [A2, B3, B7, C6, F7, H1]
Camel = B3 pawns = [H7, D5, A2, C2, D3, F7, D7, G8, A6] [A2, C2, D5, F7, G8]
class FindKillablePawnsByCamel

{    public static void main(String s[])
    {
        ChessPosition camel = new ChessPosition('C', 1);
        List pawnPositions = new ArrayList();
        pawnPositions.add(new ChessPosition('A', 3));
        pawnPositions.add(new ChessPosition('B', 2));
        pawnPositions.add(new ChessPosition('B', 1));
        pawnPositions.add(new ChessPosition('H', 6));
        pawnPositions.add(new ChessPosition('D', 3));
        pawnPositions.add(new ChessPosition('E', 3));
        pawnPositions.add(new ChessPosition('G', 3));
        pawnPositions.add(new ChessPosition('E', 2));
        System.out.println("The pawn positions which camel can kill are: " + getPossiblePawnPositions(camel, pawnPositions));

    }


public static List<ChessPosition> getPossiblePawnPositions(ChessPosition camelPosition, List<ChessPosition> pawnPositions) {
//Write code here to get possible pawn positions which a camel can kill.
}
}
class ChessPosition {

char column;
int row;

public ChessPosition(char column, int row) {
this.column = column;
this.row = row;
}

@Override
public boolean equals(Object obj) {
ChessPosition position = (ChessPosition) obj;
return column == position.column && row == position.row;
}

@Override
public String toString() {
return column + "" + row;
}
}



Arithmetic Operators Increment Decrement Compound Assignment Output36

What will be the output of the following program.
class Addition
{
    public static void main(String s[])
    {
        int a = 4;
        a -= 10;
        a = -a;
        a = 7 + a;
        System.out.println(" a = " + a );
        a %= a;
        a = a * a - 3 ;
        System.out.println(" a = " + a );
    }
}
A. a = 13
a = -3
B. a = 33
a = 163
C. a = 33
a = -3
D. Program does not compile



© meritcampus 2019

All Rights Reserved.

Open In App