[Solved] Who is the winner? [closed]

Introduction

The question of who is the winner is a common one, and it can be difficult to answer. It depends on the context of the situation and the rules that have been set. In this article, we will discuss the various ways to determine who is the winner in a given situation and how to come to a conclusion. We will also discuss the importance of having clear rules and expectations in order to ensure a fair and equitable outcome.

Solution

The winner depends on the context of the question. If the question is referring to a game or competition, then the winner would be the person or team that achieved the highest score or won the game.


It must be the bob == 0 and alice == 0 case. Put an print stamement in the else statement you will know why. Your execution is making that case somehow.

Also in issquare you should have the loop like this

for(i = 0; i <= num; i++) because for numbers like 1 it would fail.

Also there is a flaw in your logic. You should form the number

8 10 you should check 81 and 18. But in your case you don’t do this.(You check 90 and 108).

#include <stdio.h>
#include <stdlib.h>
int reverse(int num)
{
  int rev=0,inter = 0;
  while(num){ 
    inter = rev*10;
    if( inter/10 != rev){
        fprintf(stderr, "%s\n", "Overflow\n");
        exit(1);
    }
    rev=inter+num%10;
    num/=10;
  }
  return rev;
}

int issquare(int num)
{
  for(int i = 0; i <= num; i++){
    long long ii = i;
    long long mul  = ii*ii;
    if( ii!= 0 &&  mul/ii != ii){
        fprintf(stderr, "%s\n", "Overflow\n");
        exit(1);
    }
    if(mul == num)
      return 1;
    else if(mul > num){
        break;
    }
  }
  return 0;
}
int main()
{
  int num1, num2, normal, rev, alice, bob;
  if( scanf("%d%d", &num1, &num2)!= 2){
      fprintf(stderr,"Error in input\n");
      exit(1);
  }
  printf("%d %d", num1, num2);
  rev = reverse(num1+num2);
  normal = num1+ num2;
  bob = issquare(rev);
  alice = issquare(normal);
  if(bob==alice)
    printf("Tie"); 
  else if(bob > alice)
      printf("Bob wins.");
  else 
    printf("Alice wins.");
  return 0;
}

solved Who is the winner? [closed]


The answer to the question “Who is the winner?” is subjective and depends on the context. For example, if the question is referring to a sporting event, the winner would be the team or individual who achieved the highest score or placed first in the competition. If the question is referring to a game of chance, the winner would be the person who correctly guessed the outcome or had the highest score. In any case, the winner is the person or team who achieved the best result.