예제 #1
0
파일: uva10763.java 프로젝트: de-yu/uva
  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");
    }
  }
예제 #2
0
  /**
   * Return a set of the variables in the supplied expression. Note: Substitutions which are in the
   * constant table are not included.
   */
  public Set<String> getVariablesWithin(String exp) {
    Set<String> all = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
    String add = null;

    if (separators == null) {
      StringBuilder sep = new StringBuilder(10);
      for (char chr = 0; chr < operators.length; chr++) {
        if (operators[chr] != null && !operators[chr].internal) {
          sep.append(chr);
        }
      }
      sep.append("()");
      separators = sep.toString();
    }

    for (StringTokenizer tkz = new StringTokenizer(exp, separators, true); tkz.hasMoreTokens(); ) {
      String tkn = tkz.nextToken().trim();

      if (tkn.length() != 0 && Character.isLetter(tkn.charAt(0))) {
        add = tkn;
      } else if (tkn.length() == 1 && tkn.charAt(0) == '(') {
        add = null;
      } else if (add != null && !constants.containsKey(add)) {
        all.add(add);
      }
    }
    if (add != null && !constants.containsKey(add)) {
      all.add(add);
    }
    return all;
  }
 public static String nextString() throws Exception {
   for (; st == null || !st.hasMoreTokens(); ) {
     String k1 = in.readLine();
     if (k1 == null) return null;
     st = new StringTokenizer(k1);
   }
   return st.nextToken();
 }
예제 #4
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();
 }
예제 #5
0
파일: H.java 프로젝트: Mityai/nncworkspaces
 String nextToken() {
   while (st == null || !st.hasMoreTokens()) {
     try {
       st = new StringTokenizer(br.readLine());
     } catch (Exception e) {
       eof = true;
       return "0";
     }
   }
   return st.nextToken();
 }
예제 #6
0
파일: Check.java 프로젝트: alexkats/Code
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            return st.nextToken();
        }
예제 #7
0
 public static void readFile() throws Exception {
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
   StringTokenizer st = new StringTokenizer(br.readLine(), " ");
   n = Integer.valueOf(st.nextToken());
   b = new BigInteger(st.nextToken());
   int iCount = 0;
   bookHeight = new int[n];
   while (iCount < n) {
     bookHeight[iCount++] = Integer.valueOf(br.readLine());
   }
   process();
 }
예제 #8
0
파일: A.java 프로젝트: Mityai/nncworkspaces
 String nextToken() {
   while (st == null || !st.hasMoreTokens()) {
     try {
       st = new StringTokenizer(br.readLine());
     } catch (Exception e) {
       eof = true;
       break;
     }
   }
   String ret = buf;
   buf = eof ? "-1" : st.nextToken();
   return ret;
 }
예제 #9
0
파일: c.java 프로젝트: ysyshtc/Codeforces
 boolean hasNext() {
   while (tokenizer == null || !tokenizer.hasMoreTokens())
     try {
       tokenizer = new StringTokenizer(buff.readLine());
     } catch (Exception e) {
       return false;
     }
   return true;
 }
예제 #10
0
파일: A.java 프로젝트: Mityai/nncworkspaces
 String nextToken() {
   if (!createST) {
     try {
       curLine = readLine();
     } catch (Exception e) {
       eof = true;
     }
     return null;
   }
   while (st == null || !st.hasMoreTokens()) {
     try {
       curLine = readLine();
       st = new StringTokenizer(curLine);
     } catch (Exception e) {
       eof = true;
       break;
     }
   }
   String ret = buf;
   buf = eof ? "-1" : st.nextToken();
   return ret;
 }
예제 #11
0
파일: STRQ.java 프로젝트: jmankhan/ACM
  public void solve() throws Exception {
    String str = in.readLine();
    int n = str.length();

    int t = Integer.parseInt(in.readLine());

    int[][] dp = new int[26][n];

    dp[str.charAt(0) - 'a'][0] = 1;

    for (int i = 1; i < n; i++) {
      for (int j = 0; j < 26; j++) {
        if (str.charAt(i) == 'a' + j) {
          dp[j][i] = dp[j][i - 1] + 1;
        } else {
          dp[j][i] = dp[j][i - 1];
        }
      }
    }

    while (t-- > 0) {
      st = new StringTokenizer(in.readLine());
      char a = st.nextToken().toCharArray()[0];
      char b = st.nextToken().toCharArray()[0];

      int l = parseInt(st.nextToken()) - 1;
      int r = parseInt(st.nextToken()) - 1;

      int ans = 0;
      for (int i = l; i <= r; i++) {
        if (str.charAt(i) == a) {
          ans += dp[b - 'a'][r] - dp[b - 'a'][i];
        }
      }

      out.println(ans);
    }
  }
 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);
 }
예제 #13
0
파일: c.java 프로젝트: ysyshtc/Codeforces
 String next() {
   if (!hasNext()) throw new RuntimeException();
   return tokenizer.nextToken();
 }
예제 #14
0
 String next() throws IOException {
   while (!tokenizer.hasMoreTokens()) {
     tokenizer = new StringTokenizer(reader.readLine());
   }
   return tokenizer.nextToken();
 }
예제 #15
0
 String next() throws IOException {
   while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine().trim());
   return st.nextToken();
 }
 private static String nextToken() throws IOException {
   while (!tok.hasMoreTokens()) tok = new StringTokenizer(in.readLine());
   return tok.nextToken();
 }