Sunteți pe pagina 1din 2

7/22/2016

TCS:CodeVitaCodingArena

TCSNextStepTCSCareerswww.tcs.com

Logout

WelcomeCHIDVILASPUTTA

Home

CodingArena MyCompile&Run MySubmissions Graphs Feedback


TimeLeft

CodingArena

05 57 23
hr

min

sec

F
Rules&Regulations

Problem:NumberGame
AmanandJasbirareveryintelligentguysoftheirbatch.Todaytheyareplayingagame"GameofNumbers".

LaunchCodeEditor

Descriptionofgame:

1.ThereareNnumbersplacedonatable.
2.Sincetwoplayersareplayingthegame,theywillmaketheirmovesalternatively.
3.Inonemoveaplayercanperformthefollowingoperation.
a.Aplayerwillchooseanumberfromthetableandwillreplacethatnumberwithoneofitsdivisor.For
example,6canbereplacedwith1,2,or3(sincethesearethedivisorsof6).Similarly,12canbe
replacedwith1,2,3,4or6.
b.Itismandatorythattheplayerhastoreplacethenumber.
c.Aplayercannotputbackthesamenumberontable.
d.As1doesnothaveanydivisorotherthanitself,aplayercannotreplace1withanyothernumber.So
soonasituationwillarisewhentherewillbeonlyall1sonthetable.Inthatsituationtheplayerwillnot
beabletomakeanymove.Theplayerwhowillnotbeabletomakethemove,loses.
4.Boththeplayersaremastersofthisgame.Sotheywillplaythegameoptimally.
5.Amanwillmakethefirstmoveofthegame.
YouwillbegivenNintegersthatareonthetable.Youhavetopredict,whowillwinthegameAmanorJasbir.
InputFormat:
Firstlinecontainsinformationaboutthenumberspresentofthetable,denotedbyN
SecondlinecontainsNintegersdelimitedbyspaceA 1A 2A 3A 4.........A N

OutputFormat:
Printthenameoftheplayerwhowillwinthegameinuppercasei.e.AMANorJASBIR.

Constraints:
1<=N<=100000
0<A i<=10000
Aplayercannotreplacemorethan1numberinonemove.
Playersmovealternateandaplayercannotpassormakenomove.
Anumbercannotbereplaceditself,i.e.6canbereplacedwith1,2or3only,notwith6.
Amanalwaysmakesthefirstmove.

SampleInputandOutput
SNo. Input

Output

1
6

AMAN

2
186

AMAN

4
24454524

JASBIR

Explanationforsampleinputoutput1:
ThereisonlyonenumberplacedonthetabledoAMANwillreplaceitwith1.Jasbirwillplaynext.Asthereisonly1lefton
thetable.Anditcannotbereplacedwithanyothernumberheisnotabletomakeanymove.Sohelosesthegame.

Explanationforsampleinputoutput2:
Thereare2numberspresentonthetable.Sinceeverymoveistheoptimalmove,Amanwillreplace18with6.Now(6,6)

https://www.tcscodevita.com/CodevitaV5/problemstart.jsp

1/2

7/22/2016

TCS:CodeVitaCodingArena

willbeleftonthetable.Now,whatevermoveJasbirwillmake.Amanwillalsomakethesamemove.SowheneverJasbir
willreplaceanynumberwith1.InthenextmoveAmanwillalsoreplacetheothernumberwith1.Soboththenumberswill
beoneafterAman'smove.SoJasbirwilllosethegame.
Initialconfiguration(18,6)
AFTERAman'sMOVE(6,6)
AFTERJasbir'sMOVE(6,3)
AFTERAman'sMOVE(3,3)
AFTERJasbir'sMOVE(1,3)
AFTERAman'sMOVE(1,1)
Now,JasbirWILLNOTBEABLETOMAKEANYMOVE.So,AmanwillWIN.
Explanationforsampleinputoutput3:
Inthiscase,gameisalreadysymmetric.Amanhastomakethefirstmove.SowhatevermoveAmanwillmakeJasbirwill
justrepeatthesame.SoIntheAmanwillgooutofmovesandJasbirwillwinthegame.
Initialconfiguration(24,45,45,24)
AFTERAman'sMOVE(1,45,45,24)
AFTERJasbir'sMOVE(1,45,45,1)
AFTERAman'sMOVE(1,1,45,1)
AFTERJasbir'sMOVE(1,1,1,1)
Let'sseeifoutcomechangesifAmanreplaces24by6insteadof1
Initialconfiguration(24,45,45,24)
AFTERAman'sMOVE(6,45,45,24)
AFTERJasbir'sMOVE(6,45,45,6)
AFTERAman'sMOVE(6,5,45,6)
AFTERJasbir'sMOVE(6,5,5,6)
AFTERAman'sMOVE(3,5,5,6)
AFTERJasbir'sMOVE(3,5,5,3)
AFTERAman'sMOVE(1,5,5,3)
AFTERJasbir'sMOVE(1,5,5,1)
AFTERAman'sMOVE(1,1,5,1)
AFTERJasbir'sMOVE(1,1,1,1)
Now,AmanWILLNOTBEABLETOMAKEANYMOVE.So,JasbirwillWIN.ItiseasytoseethatjustbymimickingAman's
moves,Jasbirwillwin.

Note:
Pleasedonotusepackageandnamespaceinyourcode.Forobjectorientedlanguagesyourcodeshouldbewritteninone
class.
Note:
ParticipantssubmittingsolutionsinClanguageshouldnotusefunctionsfrom<conio.h>/<process.h>asthesefilesdonot
existingcc
Note:
ForCandC++,returntypeofmain()functionshouldbeint.

2016TataConsultancyServicesLimited.AllRightsReserved.

SubmitAnswer
I,CHIDVILASPUTTAconfirmthattheanswersubmittedismyown.
Browse...

2016TataConsultancyServicesLimited.AllRightsReserved. InAssociationwith

https://www.tcscodevita.com/CodevitaV5/problemstart.jsp

|PrivacyPolicy

2/2

S-ar putea să vă placă și