top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Rock Paper and Scissor Implementation in C?

+3 votes
381 views

Can someone help me with Rock Paper and Scissor Implementation in C along with the algo?

posted Nov 5, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 #include<stdio.h>
 #include<time.h>
 #include<stdlib.h>

 #define size 3

 int main()
 {
    int gVar;
    int CPU;
    int ch;
    srand(time(NULL));
    printf("Players choice: Rock 0, Paper 1, Scissor 2\n");

    do
    {
       printf("Enter your choice: Rock 0, Paper 1, Scissor 2\n");
       scanf("%d", &gVar);

       CPU = rand()%size;

       if(gVar == CPU)
       {
          printf("its a tie: Your choice = %d, CPU = %d\n", gVar, CPU);
       }
       else if(gVar < CPU)
       {
         if(gVar==0 && CPU == 2 )
         {
           printf("You Won: Your choice = %d, CPU = %d\n", gVar, CPU);
         }
         else
         {
             printf("CPU Won: Your choice =%d, CPU = %d\n", gVar, CPU);
         }

       }
       else
       {
          if(CPU == 0 && gVar == 2)
          {
             printf("CPU Won: Your Choince = %d, CPU =%d\n", gVar, CPU);
          }
          else
          {
             printf("You Won: Your Choice = %d, CPU =%d\n", gVar, CPU);
          }
       }
       printf("Enter 5 to play again\n");
       scanf("%d",&ch);

    }while(ch == 5);

    return 0;      
}
answer Nov 15, 2014 by Prakash Singh
Similar Questions
–1 vote

Given a Singly linked list with each node containing either 0, 1 or 2. Write code to sort the list.
Input : 1 -> 1 -> 2 -> 0 -> 2 -> 0 -> 1 -> 0
Output : 0 -> 0 -> 0 -> 1 -> 1 -> 1 -> 2 -> 2

+3 votes

A person has two piles of stones with him, one has n1 stones and the other has n2 stones. Fired up by boredom, he invented a game with the two piles.

  1. Before the start of the game person chooses an integer m.
  2. In the j-th move: He chooses a number xj such that 1 ≤ xj ≤ m, and removes xj stones from both the piles (this is only possible when both the piles have ≥ xj stones).
  3. The number chosen must be unique over all the moves in the game. That is, for all k < j, xj ≠ xk.
  4. The game stops when person is unable to make any more moves.
    Note: Person wants to make the moves in such a way that the sum of the number of stones remaining in the two piles is minimized.

Please help person find this.

Input
The first line of input contains an integer T denoting the number of test cases.
Each test case consists of 1 line with three integers — n1, n2 and m — separated by single spaces.

Output
For each test case, output a single line containing the minimum sum of the number of stones of two piles.

...