Beispiel #1
0
  public static void main(String[] args) throws IOException {

    Scanner scanner = new Scanner(new BufferedInputStream(System.in));
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    while (true) {
      int a = Integer.parseInt(br.readLine());
      if (a == 0) break;
      HashMap<String, Integer> map = new HashMap<String, Integer>();
      int sum = 0;

      while (a-- > 0) {
        StringTokenizer st = new StringTokenizer(br.readLine());
        int one = Integer.parseInt(st.nextToken()), two = Integer.parseInt(st.nextToken());
        country c = new country(one, two);
        country c_rev = new country(two, one);
        int s = 0;

        if (map.get(c.tostring()) != null) {
          s = map.get(c.tostring()) + 1;
          map.put(c.tostring(), s);
          sum++;
        } else if (map.get(c_rev.tostring()) != null) {
          s = map.get(c_rev.tostring()) - 1;
          map.put(c_rev.tostring(), s);
          sum--;
        } else {
          map.put(c.tostring(), 1);
          sum++;
        }
      }
      if (sum != 0) System.out.println("NO");
      else System.out.println("YES");
    }
  }
Beispiel #2
0
 public String next() {
   while (tokenizer == null || !tokenizer.hasMoreTokens()) {
     try {
       tokenizer = new StringTokenizer(reader.readLine());
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
   }
   return tokenizer.nextToken();
 }
Beispiel #3
0
 protected Locale getLocale(HttpServletRequest request) {
   String locid = request.getParameter(P_LOCALE_ID);
   if (locid == null || locid.length() == 0) {
     return request.getLocale();
   }
   StringTokenizer tokenizer = new StringTokenizer(locid, "_-");
   String language = String.valueOf(tokenizer.nextToken()).toLowerCase();
   String country = tokenizer.hasMoreTokens() ? tokenizer.nextToken() : null;
   if (country != null) {
     return new Locale(language, country.toUpperCase());
   }
   return new Locale(language);
 }
 /**
  * Returns a version of this condition in which the variable names are converted to the names that
  * will be used by the java class written to fileText. Instances of "this." are removed. Instances
  * of the package and class names prefixing variable names are removed and appended to the
  * variable name with a "_" separating the two parts. Instance of public field name suffixing a
  * variable name are removed and appended to the end of variable name with a "_" separating the
  * two parts. Instances of "orig(variableName)" are replaced by instances of "orig_variableName".
  * For example "orig(varName.publicField)" would yield "orig_varName_publicField".
  *
  * @param condition a string representation of a conditional statement.
  * @return a version of the conditional with the variable names converted.
  */
 private static String convertVariableNames(String condition, String className, VarInfo[] varInfos)
     throws ParseException {
   // These methods keep converting between strings and jtb syntax trees
   // because the visitor cause the trees to become invalid.  Therefore,
   // it is needed to re-parse the condition in a new jtb syntax tree each
   // time.  (All the parsing is hidden in the static methods.)
   condition = ThisRemover.removeThisDot(condition);
   StringTokenizer classNameTokens = new StringTokenizer(className, ".");
   while (classNameTokens.hasMoreTokens()) {
     String nextToken = classNameTokens.nextToken();
     condition = PrefixRemover.removePrefix(condition, nextToken);
   }
   condition = OrigFixer.fixOrig(condition);
   condition = PrefixFixer.fixPrefix(condition);
   String[] baseNames = getBaseNames(varInfos, className);
   condition = ArrayFixer.fixArrays(condition, baseNames, varInfos);
   return condition;
 }
 public static void main(String[] args) throws Exception {
   BufferedReader st = new BufferedReader(new InputStreamReader(System.in));
   StringTokenizer s;
   s = new StringTokenizer(st.readLine());
   int n = Integer.parseInt(s.nextToken());
   int r = Integer.parseInt(s.nextToken()) - 1;
   visited = new int[n];
   int i, a, b;
   for (i = 0; i < n; i++) {
     adjList.add(new ArrayList<Integer>());
   }
   for (i = 0; i < n - 1; i++) {
     s = new StringTokenizer(st.readLine());
     a = Integer.parseInt(s.nextToken());
     b = Integer.parseInt(s.nextToken());
     adjList.get(a - 1).add(b - 1);
     adjList.get(b - 1).add(a - 1);
     visited[a - 1] = 0;
     visited[b - 1] = 0;
   }
   dfs(r, 0);
   System.out.println(maxh + " " + minh);
 }
Beispiel #6
0
 public StringBuffer construct_lucene_dc(StringBuffer result, SolrDocument d) {
   for (String field : (d.getFieldNames())) {
     StringTokenizer dcfields = new StringTokenizer(this.config.getProperty("dcfields", ","));
     while (dcfields.hasMoreTokens()) {
       String dcfield = dcfields.nextToken().trim().replaceAll(",", "");
       if (field.equalsIgnoreCase(dcfield)) {
         Iterator j = d.getFieldValues(field).iterator();
         String rename = this.config.getProperty("solr." + field);
         if (rename != null) {
           field = rename;
         } else {
           field = "dc:" + field;
         }
         while (j.hasNext()) {
           result.append("<" + field + ">");
           result.append(helpers.xmlEncode((String) j.next()));
           field = field.split(" ")[0];
           result.append("</" + field + ">");
         }
       }
     }
   }
   return (result);
 }