Monday 11 February 2013

A Game with Numbers

// C code for 1419. A Game with Numbers Problem code: NGM

#include<stdio.h>
int main()
{
    int n;
    while (scanf("%d",&n)==1)
        (n%10)?(printf("1\n%d\n",n%10)):(printf("2\n"));
    return 0;
}

4 comments:

  1. Please explain the sample output, and how did you thought about the solution of NGM.

    ReplyDelete
  2. logic is very easy if u can give you opponent a num which is divisible by 10 he'll always loose because he can not change that num to another num which is divible by 10 as he can only subtract 0-9. so player1 always subtract the last digit of number(num%10). if player1 gets num which is divisble by 10 in starting itself then by same logic he'll loose the game !

    ReplyDelete
  3. could you give me an input where trofim win? (first line output 2)

    ReplyDelete
  4. Excellent publish, very informative. I just stumbled upon your blog and wished to say that I have really enjoyed browsing your blog posts.

    ReplyDelete