/* Author: Pranav Yanambakkam
Contest 3
Programming Problem
Date: 03/15/2013 */
import
java.util.Scanner;
public class
Contest3{
public static void main(String[] args)
{
int intLineNumber = 1;
while(intLineNumber < 6)
//execute piece of code five times
{
int iSafeCells = 24;
System.out.println("Enter
Line " + intLineNumber + " : ");
Scanner in = new
Scanner(System.in);
String strInputLine =
in.nextLine();
String[] LineInput =
strInputLine.split(",");
if(LineInput.length != 3)
{
System.out.println("Invalid
Input : " + strInputLine);
}
else
{
int iRow =
Integer.parseInt(LineInput[0].trim());
int iCol =
Integer.parseInt(LineInput[1].trim());
int iMoveCells = Integer.parseInt(LineInput[2].trim());
if(iRow >= 1
&& iRow <= 5 && iCol >= 1 && iCol <= 5
&& iMoveCells >=1 && iMoveCells <=4)
{
for(int iLoop=1;
iLoop <= iMoveCells; iLoop++)
{
//Queen
moves right
if(iCol + iLoop <= 5)
{
iSafeCells--;
}
//Queen
moves left
if(iCol -
iLoop >=1)
{
iSafeCells--;
}
//Queen
moves up
if(iRow +
iLoop <= 5)
{
iSafeCells--;
}
//Queen
moves down
if(iRow -
iLoop >=1)
{
iSafeCells--;
}
//Queen
moves up and right
if((iRow +
iLoop <= 5) && (iCol + iLoop <=5))
{
iSafeCells--;
}
//Queen
moves down and left
if((iRow -
iLoop >=1) && (iCol - iLoop >=1))
{
iSafeCells--;
}
//Queen
moves up and left
if((iRow +
iLoop <= 5) && (iCol - iLoop >=1))
{
iSafeCells--;
}
//Queen
moves down and right
if((iRow -
iLoop >=1) && (iCol + iLoop <=5))
{
iSafeCells--;
}
}
System.out.println("Number
of Locations where chess piece is safe : " + iSafeCells);
intLineNumber++; //increment line number
}
else
{
System.out.println("Invalid
Input : " + strInputLine);
}
}
}
}
}