Wednesday 14 December 2011

2727. ARMY STRENGTH

Summary:- 
Well problem is pretty simple.... Both Godzilla and MechaGodzilla have soldiers of different strength and there will be random fight between individual soldiers and winner in this fight will be based on simple condition-->
Strength of Godzilla soldier >= Strength of MechaGodzilla soldier(obviously... Godzilla one wins)
Strength of Godzilla soldier < Strength of MechaGodzilla soldier(obviously... MechaGodzilla one wins)
Otherwise "uncertain"(Yup... you are right.... this never happens) 

 This continues for every soldier and the team whose soldiers remain is declared winner by the above mentioned criteria.

Logic:-
What I did is I took input of strengths in an array of required size and then found out the greatest integer in both the array and then compared it according the above criteria to score an AC
Here's the code in C.


#include<stdio.h>
int main()
{
 int t;
 scanf("%d",&t);
 int i;
 int j;
 int ng;
 int nm;
 int m1;
 int m2;
 for(i=0;i<t;i++) {
  scanf("%d",&ng);
  scanf("%d",&nm);
  int g[ng];
  int m[nm];
  for(j=0;j<ng;j++) {
   scanf("%d",&g[j]);
  }
  for(j=0;j<nm;j++) {
   scanf("%d",&m[j]);
  }
  m1=g[0];
  m2=m[0];
  for(j=1;j<ng;j++) {
   if(m1<g[j])
   m1=g[j];
  }
  for(j=1;j<nm;j++) {
   if(m2<m[j])
   m2=m[j];
  }
  if(m1>=m2)
   printf("Godzilla\n");
  else if(m1<m2)
   printf("MechaGodzilla\n");
  else
   printf("uncertain\n");
 }
 return 0;
}

4 comments:

  1. My logic is same, but in python, still I am getting the WA. What could be the problem. Are there any special test cases.

    ReplyDelete
  2. my code is also same in c++...still I'm getting WA ...what to do?

    ReplyDelete