예제 #1
0
  public static void main(String[] args) {
    // TODO Auto-generated method stub

    Scanner in = new Scanner(System.in);
    Hashtable numbers = new Hashtable();

    N = in.nextInt();
    K = in.nextLong();

    long[] arr = new long[N];
    for (int i = 0; i < N; i++) {
      arr[i] = in.nextLong();
      numbers.put(Long.toString(arr[i]), arr[i]);
    }

    result = 0;

    for (int i = 0; i < N; i++) {
      long tmp = 0, tmp2 = 0;
      tmp = arr[i] + K;
      try {
        tmp2 = (Long) numbers.get(Long.toString(tmp));
        result++;
      } catch (Exception ex) {

      }
    }

    System.out.println(result);
  }
예제 #2
0
  public static LinkedList<profile> importer() throws IOException {

    LinkedList<profile> people = new LinkedList<profile>();
    Scanner sFile;
    profile entry;

    try {
      sFile =
          new Scanner(new File("/Users/richarddavies/NetBeansProjects/typ_MatlabGraph/users.dat"));
      sFile.nextLine();
      while (sFile.hasNext()) {

        String profile = sFile.nextLine();
        // System.out.println(profile);

        Scanner profScan = new Scanner(profile);
        profScan.useDelimiter(",");

        while (profScan.hasNext()) {

          Long id = profScan.nextLong();
          String ident = String.valueOf(id);
          String rot_Id = rot13.encrypt(ident);
          Long rot_IntId = Long.parseLong(rot_Id);

          String fname = profScan.next();
          String rot_Name = rot13.encrypt(fname);
          // String sname = profScan.next();
          // int age = profScan.nextInt();
          String gender = profScan.next();
          String nat = profScan.next();

          entry = new profile(id, fname, gender, nat);
          // System.out.println("id: "+id+" name: "+fname+" gender: "+gender+" nationality: "+nat);
          // System.out.println("id: "+rot_IntId+" name: "+rot_Name+" gender: "+gender+"
          // nationality: "+nat);
          people.add(entry);
        }
      }

    } catch (IOException ex) {
      // return people;

      System.out.println("(No System File profile.txt)" + ex);
    }
    return people;
  }
예제 #3
0
파일: edge.java 프로젝트: mo0o/Sociograph
  public static LinkedList<edge> importer(MatlabProxy proxy)
      throws IOException, MatlabConnectionException, MatlabInvocationException {

    Scanner sFile;
    edge entry;
    LinkedList<edge> tie = new LinkedList<edge>();
    Long k, p;

    try {
      sFile =
          new Scanner(new File("/Users/richarddavies/NetBeansProjects/typ_MatlabGraph/edges.dat"));

      System.out.println(sFile.nextLine());

      while (sFile.hasNext()) {

        String edge = sFile.nextLine();
        // System.out.println(edge);

        Scanner edgeScan = new Scanner(edge);
        edgeScan.useDelimiter(",");

        while (edgeScan.hasNext()) {

          k = edgeScan.nextLong();
          System.out.print(k + " ");

          String ident_k = String.valueOf(k);
          String rot_Id_k = rot13.encrypt(ident_k);
          Long rot_k = Long.parseLong(rot_Id_k);

          p = edgeScan.nextLong();
          System.out.print(p);

          String ident_p = String.valueOf(p);
          String rot_Id_p = rot13.encrypt(ident_p);
          Long rot_p = Long.parseLong(rot_Id_p);

          // System.out.println(rot_k+" : "+rot_p);
          entry = new edge(k, p);

          int n = search.search(k);
          int m = search.search(p);
          System.out.print(
              " : "
                  + Typ_MatlabGraph.people.get(n).idProf
                  + " "
                  + Typ_MatlabGraph.people.get(m).idProf);
          System.out.println("");
          n++;
          m++;

          proxy.eval("adjMatrix(" + n + "," + m + ") = 1");

          tie.add(entry);
        }
      }

    } catch (IOException ex) {

      System.out.println("(No System File profile.txt)" + ex);
    }

    return tie;
  }