06/10/2013

10919 - Prerequisites? - Java

 package org.goro.uva.m;  
 import java.io.*;  
 import java.math.RoundingMode;  
 import java.text.NumberFormat;  
 import java.util.*;  
 public class Prerequisites {  
      public static char[] ch_name1 = new char[25];  
      public static char[] ch_name2 = new char[25];  
      public static void main(String[] args) throws Exception {  
 //          Reader.init(new FileInputStream(new File("input.in")));  
           Reader.init(System.in);  
           StringBuilder sb = new StringBuilder();  
           int noOfCourses = Reader.nextInt();  
           int noOfCat;  
           while (noOfCourses > 0) {  
                noOfCat = Reader.nextInt();  
                int coursesTaken[] = new int[noOfCourses];  
                boolean isValid = true;  
                for(int i = 0; i < noOfCourses; i++) coursesTaken[i] = Reader.nextInt();  
                for(int i = 0; i < noOfCat; i++) {  
                     int tempNoCourses = Reader.nextInt();  
                     int mustHave = Reader.nextInt();  
                     int validated = 0;  
                     for(int j = 0; j < tempNoCourses; j++) {  
                          int tempCurse = Reader.nextInt();  
                          for (int k : coursesTaken) {  
 //                              System.out.println("Checking course: " + tempCurse + " k: " + k);  
                               if (tempCurse == k) {  
                                    validated++;  
                                    break;  
                               }  
                          }  
                     }  
                     if(validated < mustHave) {  
                          isValid = false;  
 //                         System.out.println("Valid: " + validated + " must have: " + mustHave);  
                     }  
                }  
                if(isValid) sb.append("yes\n");  
                else sb.append("no\n");  
                noOfCourses = Reader.nextInt();  
           }  
           System.out.print(sb);  
      }  
 }  
 /** Class for buffered reading int and double values */  
 /** http://www.cpe.ku.ac.th/~jim/java-io.html */  
 class Reader {  
      static BufferedReader reader;  
      static StringTokenizer tokenizer;  
      /** call this method to initialize reader for InputStream */  
      static void init(InputStream input) {  
           reader = new BufferedReader(new InputStreamReader(input));  
           tokenizer = new StringTokenizer("");  
      }  
      /** get next word */  
      static String next() throws IOException {  
           while (!tokenizer.hasMoreTokens()) {  
                tokenizer = new StringTokenizer(reader.readLine());  
           }  
           return tokenizer.nextToken();  
      }  
      static int nextInt() throws IOException {  
           return Integer.parseInt(next());  
      }  
      static double nextDouble() throws IOException {  
           return Double.parseDouble(next());  
      }  
 }  

1 comment:


  1. A SQL query goes into a bar, walks up to two tables and asks, "Can I join you?"

    ReplyDelete