NailsProblem code: TECH06 |
One fine day during the summer break Aman and Anish were playing in the tool shed with some nails. Being the little pesky kids that they were, they enjoyed hammering nails into anything they could find. Seeing this their father decided to make their little nail hammering nuisance into more of a learning activity. He proposed a game to the two boys: "I will give you a nail of some particular length , each of you have to take turns to hammer it into a piece of wood. The person who hammers the nail in last loses the game."
Now Anish and Aman having similar physical ability could hit the nail inside a piece of would a maximum of 'B' inches and a minimum of 'A' inches inclusive. Anish always starts the game.
Given a nail of length 'L' inches and the integers 'A' and 'B', you have to determine the winner of this game assuming both Anish and Aman play optimally.
Input
First line consists the number of testcases 'T'. The next 'T' lines consist of three space separated integers A, B, L such that 1 < A < B < 1,000,000 and 1 < L < 1000,000,000
Output
Output either 'Anish' or 'Aman' on a new line indicating the winner of the game for each test case.
Example
Input: 2 3 9 12 3 9 13 Output: Anish Aman
| Author: | technovanza10 |
| Date Added: | 12-01-2010 |
| Time Limit: | 2 sec |
| Source Limit: | 50000 Bytes |
| Languages: | C, C99 strict, CLOJ, CPP 4.0.0-8, CPP 4.3.2, F#, GO, JAVA, PERL6, PYTH 3.1.2, TEXT |
Comments

Fetching successful submissions

import java.util.*;class
import java.util.*;
class Main
{
public static void main(String args[])
{
//System.out.print();
Scanner sa=new Scanner(System.in);
int n=Integer.parseInt(sa.nextLine());
String in[]=new String[n];
for(int i=0;i<n;i++)
{
String s=sa.nextLine();
String num[]=s.split(" ");
int aman=Integer.parseInt(num[0]);
int anish=Integer.parseInt(num[1]);
int len=Integer.parseInt(num[2]);
int current=len;
boolean turn=true;
while(current>0)
{
if(turn)
{
current=current-anish;
}
else
{
current=current-aman;
}
turn=!(turn);
}
if(turn)
in[i]="Anish";
else
in[i]="Aman";
}
for(int k=0;k<n;k++)
{
System.out.println(in[k]);
}
}
}