3628 - Blue Jeans North America - South Central - 2006/2007

The forum to report every bug you find or tell us what you'd like to find in Live Archive

Moderator: Board moderators

3628 - Blue Jeans North America - South Central - 2006/2007

Postby Darko » Thu Nov 16, 2006 6:26 am

I guess this is the best way to ask a question...

Did you add something to input of this program? I got the judge data and my Java solution works just fine. I can't buy an AC here, though.

Here is the code (remove it if you think it is inappropriate):
Code: Select all
import java.io.IOException;
import java.util.Enumeration;
import java.util.Hashtable;

class Main {

   void work() {
      int nc = parseInt(readLine());
      while (nc-- > 0) {
         int n = parseInt(readLine());
         String[] ss = new String[n];
         for (int i = 0; i < n; i++) {
            ss[i] = readLine();
         }
         Hashtable[] sets = new Hashtable[n];
         for (int i = 0; i < n; i++) {
            sets[i] = new Hashtable();
            for (int j = 3; j <= 60; j++) {
               for (int k = 0; k + j <= 60; k++) {
                  String sub = ss[i].substring(k, k + j);
                  sets[i].put(sub, "");
               }
            }
         }

         String res = "";
         Enumeration e = sets[0].keys();
         while (e.hasMoreElements()) {
            String next = (String) e.nextElement();
            boolean ok = true;
            for (int i = 1; i < n; i++) {
               if (!sets[i].containsKey(next)) {
                  ok = false;
                  break;
               }
            }
            if (ok && next.length() > res.length())
               res = next;
         }

         if (res.length() == 0)
            res = "no significant commonalities";
         System.out.println(res);
      }
   }

   private String readLine() {
      StringBuffer sb = new StringBuffer();
      int b = 0;
      while (b != '\n' && b >= 0) {
         try {
            b = System.in.read();
         } catch (IOException e) {
            return null;
         }
         if (b != '\r' && b != '\n' && b >= 0)
            sb.append((char) b);
      }
      if (sb.length() == 0 && b < 0)
         return null;
      return sb.toString().trim();
   }

   private int parseInt(String s) {
      int result = 0;
      int sign = (s.charAt(0) == '-') ? -1 : 1;
      if (sign == -1)
         s = s.substring(1);
      if (s.charAt(0) == '+')
         s = s.substring(1);
      int i = 0, max = s.length();
      if (max > 0) {
         while (i < max) {
            result *= 10;
            result += s.charAt(i++) - 48;
         }
      }
      return sign * result;
   }

   public static void main(String args[]) {
      Main myWork = new Main();
      myWork.work();
   }
}
Darko
Experienced poster
 
Posts: 72
Joined: Fri Nov 11, 2005 8:34 am
Location: Calgary, Canada

Postby Carlos » Mon Jan 22, 2007 6:15 pm

up
DON'T PM ME --> For any doubt, suggestion or error reporting, please mail to:
acmicpclivearchive@gmail.com
User avatar
Carlos
System administrator
 
Posts: 634
Joined: Sat Oct 13, 2001 1:00 am
Location: Valladolid, Spain

Postby Carlos » Sat Feb 03, 2007 2:21 pm

I've PM you with a test case that your program can't handle.
DON'T PM ME --> For any doubt, suggestion or error reporting, please mail to:
acmicpclivearchive@gmail.com
User avatar
Carlos
System administrator
 
Posts: 634
Joined: Sat Oct 13, 2001 1:00 am
Location: Valladolid, Spain


Return to Bugs and Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests

cron