10530 - Guessing Game

All about problems in Volume CV. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Re: 10530 - Guessing Game

Postby brianfry713 » Tue Aug 14, 2012 12:01 am

8
too high
10
right on
0
brianfry713
Guru
 
Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10530 - Guessing Game

Postby engnaruto » Tue Nov 27, 2012 10:07 pm

hello
i made a code for this problem and the output of the program all is right but still WA
what should i do ?????

Code: Select all
import java.util.Scanner;

public class GuessingGame {

   public static void main(String[] args) {

      Scanner input = new Scanner(System.in);
      int n = 0;
      String s = "";
      int h = 0;
      int y = 0;
      int z = 0;
      int oop = 0;
      int[] x = new int[10];
      int[] xx = new int[10];
      for (int i = 0; i < 10; i++) {
         x[i] = 0;

      }

      while (input.hasNext()) {

         n = input.nextInt();
         if (n == 0) {
            break;
         }
         input.nextLine();
         s = input.nextLine();

         if (s.equals("too high")) {
            xx[n - 1]++;
            if (xx[n - 1] <= 2 && x[n - 1] == -1) {
               oop = 1;
            }
            x[n - 1] = 1;
         } else if (s.equals("too low")) {
            xx[n - 1]++;
            if (xx[n - 1] <= 2 && x[n - 1] == 1) {
               oop = 1;
            }
            x[n - 1] = -1;
         } else if (s.equals("right on")) {
            if (x[n - 1] == 1 || x[n - 1] == -1) {
               oop = 1;
            }
            x[n - 1] = 2;

            for (int j = 0; j < x.length; j++) {
               if (x[0] == 0) {

                  x[0] = -1;

               } else if (x[9] == 0) {

                  x[9] = 1;

               }

               if (x[j] == 0 && x[j - 1] == 2) {

                  x[j] = 1;

               } else if (x[j] == 0) {

                  x[j] = x[j - 1];
               }

            }


            // //////////////y = 0,1//////////////

            for (int i = n; i < x.length; i++) {
               if (x[i] == 1) {
                  y = 1;
               } else {
                  y = 0;
                  break;
               }
            }
            // /////////////z = 0,1//////////
            for (int i = 0; i < n - 1; i++) {
               if (x[i] == -1) {
                  z = 1;
               } else {
                  z = 0;
                  break;
               }

            }

            // /////////////h = 1/////////

            if (x[0] == 2) {

               for (int i = 1; i < x.length; i++) {
                  if (x[i] == 1) {
                     h = 1;

                  } else {
                     h = -1;
                     break;
                  }
               }

            } else if (x[9] == 2) {
               for (int i = 1; i < x.length - 1; i++) {
                  if (x[i] == -1) {
                     h = 1;

                  } else {
                     h = -1;
                     break;
                  }
               }
            }

            
            int xxc = 0;
            // ////////////////Special Cases///////////////////////
            if (oop == 1) {
               System.out.println("Stan is dishonest");
               xxc = 1;
            } else if (x[0] == 2 && h == 1) {
               System.out.println("Stan may be honest");
               xxc = 1;
            } else if (x[0] == 2 && h == -1) {
               System.out.println("Stan is dishonest");
               xxc = 1;
            } else if (x[9] == 2 && h == 1) {
               System.out.println("Stan may be honest");
               xxc = 1;
            } else if (x[9] == 2 && h == -1) {
               System.out.println("Stan is dishonest");
               xxc = 1;
            }
            int oo = 0;
            // /////////////////////////////
            for (int i = 1; i < x.length - 1; i++) {
               // if (x[i] == 2 && x[i - 1] == -1 && x[i + 1] == 1) {
               if (x[i] == 2 && y == 1 && z == 1 && oop == 0) {
                  System.out.println("Stan may be honest");
                  oo = 0;
                  break;
               } else {
                  oo = 1;
               }

            }
            if (oo == 1 && oop == 0 && xxc == 0) {
               System.out.println("Stan is dishonest");
            }

            // ///////////////////////////

            for (int i = 0; i < x.length; i++) {
               x[i] = 0;
            }
            oop = 0;
            oo = 0;
            xxc = 0;
         
         }

      }

   }
}
engnaruto
New poster
 
Posts: 2
Joined: Wed Nov 07, 2012 7:41 pm

Re: 10530 - Guessing Game

Postby brianfry713 » Fri Nov 30, 2012 7:08 am

brianfry713
Guru
 
Posts: 1861
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Previous

Return to Volume CV

Who is online

Users browsing this forum: No registered users and 1 guest