Friday 21 July 2017

SPOJ : NGM Solution

Question :NGM - A Game with Numbers
This problem must be given some time to tinker the brains  
Explaination 
If the largest digit is at the unit's place,then 1st player has to substract it and number becomes ".....0".Now,if you use pen on paper to solve it eg. 58 makes payer1 to win, 64 makes player2 to win.
64 , 58 , 50, 45, 40 ,36, 30 ,27, 20, 18 , 10,9->0


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<iostream>
#define LL long long
#define mx 10010
using namespace std;

int main()
{
    char ss[12];
    scanf("%s",ss);
    int l=strlen(ss);

    int i=0,lar=ss[0]-'0',pos=0,k=0;
    for (i=1;i<l;i++)
    {
        k=ss[i]-'0';
        if(k>lar) lar=k,pos=i;
    }
    if(pos==l-1)
        printf("1\n%d\n",lar);
    else
        printf("2\n");

    return 0;
}

 

No comments:

Post a Comment

SPOJ : MARBLES Solution

Question  MARBLES - Marbles Explaination.... Fill n spaces , with k colors. First select k spaces with k-different color.  Now we are l...