public String getRedirect(String host, boolean isRobots) {
    String result = null;
    try {
      Socket socket = new Socket(getDomain(host), 80);
      PrintWriter writer = new PrintWriter(socket.getOutputStream());

      if (!isRobots) {
        writer.print("GET " + getPath(host) + " HTTP/1.1\r\n");
        writer.print("Host: " + getDomain(host) + "\r\n");
        writer.print("\r\n");
        writer.flush();
      } else {
        writer.print("GET /robots.txt HTTP/1.1\r\n");
        writer.print("Host: " + host + "\r\n");
        writer.print("\r\n");
        writer.flush();
      }
      BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      String line = "";

      String target = "Location: http://";
      int targetCount = 0;
      boolean startNotingRedirectHost = false;
      String redirectHost = "";

      while ((line = reader.readLine()) != null) {
        for (int i = 0; i < line.length(); i++) {
          if (targetCount == target.length()) {
            targetCount = 0;
            startNotingRedirectHost = true;
          }

          if (startNotingRedirectHost) {
            if (line.charAt(i) != '\n') redirectHost = redirectHost + line.charAt(i);
          }

          if (line.charAt(i) == target.charAt(targetCount)) {
            targetCount++;
          } else {
            targetCount = 0;
          }
        }
        if (startNotingRedirectHost) {
          startNotingRedirectHost = false;
          return redirectHost;
        }
      }
      reader.close();
      socket.close();
    } catch (IOException e) {
      return null;
    }

    return result;
  }
  static void eliminarLugarFicheroLOC(Lugar lugar) {
    String fichero = lugar.getFicheroLOC();

    try {
      FileReader fr = new FileReader(fichero);
      BufferedReader br = new BufferedReader(fr);

      String linea;
      ArrayList lineas = new ArrayList();

      do {
        linea = br.readLine();
        if (linea != null) {
          if (!linea.substring(0, lugar.nombre.length()).equals(lugar.nombre)) lineas.add(linea);
        } else break;
      } while (true);
      br.close();
      fr.close();

      FileOutputStream fos = new FileOutputStream(fichero);
      PrintWriter pw = new PrintWriter(fos);

      for (int i = 0; i < lineas.size(); i++) pw.println((String) lineas.get(i));
      pw.flush();
      pw.close();
      fos.close();

    } catch (FileNotFoundException e) {
      System.err.println("error: eliminando " + e);

    } catch (IOException e) {
      System.err.println("error: eliminando 2 : " + e);
    }
  }
  /*
   * show software components
   */
  protected void showComponents(
      HttpServletRequest request, HttpServletResponse response, HttpSession session)
      throws IOException, ServletException {
    Iterator compIterator;
    int rowID = 1;

    VendorDBConnector vendorDBConnector = new VendorDBConnector();
    compIterator =
        vendorDBConnector.getSoftwareComponents((String) session.getAttribute("name")).iterator();

    response.setContentType("text/xml; charset=UTF-8");
    PrintWriter out = response.getWriter();
    out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    out.write("<rows>");

    while (compIterator.hasNext()) {
      SoftwareComponent comp = (SoftwareComponent) compIterator.next();
      out.write(
          "<row id=\""
              + (rowID++)
              + "_"
              + comp.getSoftwareID()
              + "_"
              + comp.getName()
              + "\">"
              + "<cell style='font-weight:bold;color: #055A78;'>"
              + comp.getName()
              + "</cell><cell>"
              + comp.getVersion()
              + "</cell>"
              // + "<cell>Delete^../VendorManager?op=delete_software&amp;software_id="+
              // comp.getSoftwareID()+ "^_self</cell>"
              + "<cell>Delete Software^javascript:deletesoftcomp("
              + comp.getSoftwareID()
              + ")^_self</cell>"
              // + "<cell>Update^../VendorManager?op=load_software_reg&amp;software_id=" +
              // comp.getSoftwareID()
              // + "&amp;software_name=" + comp.getName() + "&amp;software_version=" +
              // comp.getVersion()
              // + "^_self</cell>"
              + "<cell type=\"img\">../js/dhtmlxSuite/dhtmlxTree/codebase/imgs/xsd.png^Schemas^../DIController?op=show_schema&amp;xsd="
              + rowID
              + "_"
              + comp.getNum_xsds()
              + "_"
              + comp.getSoftwareID()
              + "^_self</cell>"
              + "<cell type=\"img\">../js/dhtmlxSuite/dhtmlxTree/codebase/imgs/wsdl.png^Services^../DIController?op=show_service&amp;service="
              + rowID
              + "_"
              + comp.getNum_services()
              + "_"
              + comp.getSoftwareID()
              + "^_self</cell>"
              + "</row>");
    }

    out.write("</rows>");
    out.flush();
  }
	public static void main(String[] args) throws IOException {
		Scanner scan = new Scanner(System.in);
		int test = scan.nextInt();
		double limit;
		while (test-- > 0) {
			limit = scan.nextDouble();
			n = scan.nextInt();
			V = 0;
			mm = new int[n];
			pp = new float[n];
			for (int i = 0; i < n; i++) {
				mm[i] = scan.nextInt();
				pp[i] = scan.nextFloat();
				V += mm[i];
			}
			dp = new float[V + 1];
			Arrays.fill(dp, 0);
			dp[0] = 1;
			for (int i = 0; i < n; i++)
				ZeroPack(mm[i], 1 - pp[i]);

			for (int i = V; i >= 0; i--)
				if (dp[i] > 1 - limit) {
					out.println(i);
					break;
				}

		}
		out.flush();
		out.close();
	}
Beispiel #5
0
 public String toString() {
   StringWriter writer = new StringWriter();
   PrintWriter out = new PrintWriter(writer);
   print(out);
   out.flush();
   return writer.toString();
 }
Beispiel #6
0
 public static void main(String[] args) {
   String z = in.next();
   int k = in.nextInt();
   int s = in.nextInt() - 1;
   int l = in.nextInt();
   int[] t = new int[l];
   for (int i = 0; i < l; ++i) {
     t[i] = in.nextInt() - 1;
   }
   int[][] f = new int[z.length()][k];
   for (int i = 0; i < k; ++i) {
     for (int j = 0; j < z.length(); ++j) {
       f[j][i] = in.nextInt() - 1;
     }
   }
   boolean[][] g = new boolean[z.length()][k];
   for (int i = 0; i < k; ++i) {
     for (int j = 0; j < z.length(); ++j) {
       g[j][i] = (in.nextInt() == 0);
     }
   }
   DFA dfa = new DFA(z.toCharArray(), k, s, t, f, g);
   int n = in.nextInt();
   out.println(dfa.count(n));
   out.flush();
 }
Beispiel #7
0
    /** Starts receiving and broadcasting messages. */
    public void run() {
      PrintWriter out = null;
      try {
        out = new PrintWriter(new OutputStreamWriter(incoming.getOutputStream()));

        // inform the server of this new client
        ChatServer.this.addClient(out);

        out.print("Welcome to JavaChat! ");
        out.println("Enter BYE to exit.");
        out.flush();

        BufferedReader in = new BufferedReader(new InputStreamReader(incoming.getInputStream()));
        for (; ; ) {
          String msg = in.readLine();
          if (msg == null) {
            break;
          } else {
            if (msg.trim().equals("BYE")) break;
            System.out.println("Received: " + msg);
            // broadcast the receive message
            ChatServer.this.broadcast(msg);
          }
        }
        incoming.close();
        ChatServer.this.removeClient(out);
      } catch (Exception e) {
        if (out != null) {
          ChatServer.this.removeClient(out);
        }
        e.printStackTrace();
      }
    }
  public void solve() throws IOException {
    MyReader in = new MyReader();
    PrintWriter out = new PrintWriter(System.out);

    while (true) {
      int n = in.nextInt();
      if (n == 0) break;
      int m = in.nextInt(), g = in.nextInt(), score[] = new int[m];
      for (int i = 0; i < m; i++) score[i] = in.nextInt();

      Student students[] = new Student[n];
      for (int i = 0; i < n; i++) {
        String name = in.next();
        int cnt = in.nextInt(), totScore = 0;
        for (int j = 0; j < cnt; j++) totScore += score[in.nextInt() - 1];
        students[i] = new Student(name, totScore);
      }
      Arrays.sort(students);

      int pass_cnt = 0;
      for (; pass_cnt < n && students[pass_cnt].getScore() >= g; pass_cnt++) ;
      out.println(pass_cnt);
      for (int i = 0; i < pass_cnt; i++) students[i].print(out);

      out.flush();
    }
  }
  public void doGet(HttpServletRequest req, HttpServletResponse res)
      throws IOException, ServletException {
    res.setContentType("text/html");
    try {
      PrintWriter pw = res.getWriter();
      pw.println("<html><head><TITLE>Web-Enabled Automated Manufacturing System</TITLE></head>");
      pw.println(
          "<body><br><br><br><form name=modifyuser method=post action='http://peers:8080/servlet/showUser')");
      v = U.allUsers();
      pw.println("<table align='center' border=0> <tr><td>");
      pw.println(
          "Select User Name To Modify</td><td><SELECT id=select1 name=uid style='HEIGHT: 22px; LEFT: 74px; TOP: 222px; WIDTH: 155px'>");
      pw.println("<OPTION selected value=''></OPTION>");
      for (i = 0; i < v.size(); i++)
        pw.println(
            "<OPTION value="
                + (String) v.elementAt(i)
                + ">"
                + (String) v.elementAt(i)
                + "</OPTION>");
      pw.println(
          "</SELECT></td></tr><tr><td></td><td><input type='submit' name='submit' value='Submit'></td></tr></table></form></body></html>");
      pw.flush();
      pw.close();

    } catch (Exception e) {
    }
  }
  /**
   * GML (Graph Modeling Language) is a text file format supporting network data with a very easy
   * syntax. It is used by Graphlet, Pajek, yEd, LEDA and NetworkX.
   */
  public void exportAsGML(File gmlFile, List<SemanticPath> paths) {
    gmlFile.getParentFile().mkdirs();

    try (PrintWriter writer = new PrintWriter(Files.newWriter(gmlFile, Charsets.UTF_8)); ) {

      writer.println("graph\n[");
      // write vertex
      for (SemanticPath path : paths) {
        for (int i = 0; i < path.length(); i++) {
          writer.println("\tnode\n\t[");
          writer.println("\t\tid " + path.id(i));
          writer.println("\t\tlabel \"" + path.name(i) + "\"");
          writer.println("\t]");
        }
      }

      // write edge
      for (SemanticPath path : paths) {
        for (int i = 0; i < path.length() - 1; i++) {
          writer.println("\tedge\n\t[");
          writer.println("\t\tsource " + path.id(i + 1));
          writer.println("\t\ttarget " + path.id(i));
          writer.println("\t]");
        }
      }
      writer.println(']');
      writer.flush();
    } catch (IOException e) {
      LOG.error("Export to GML file error!", e);
    }
  }
Beispiel #11
0
  public void doGetDDS(ReqState rs) throws Exception {
    HttpServletResponse response = rs.getResponse();

    GuardedDataset ds = null;
    try {
      ds = getDataset(rs);
      if (null == ds) return;

      response.setContentType("text/plain");
      response.setHeader("XDODS-Server", getServerVersion());
      response.setHeader("Content-Description", "dods-dds");

      OutputStream out = new BufferedOutputStream(response.getOutputStream());
      ServerDDS myDDS = ds.getDDS();

      if (rs.getConstraintExpression().equals("")) { // No Constraint Expression?
        // Send the whole DDS
        myDDS.print(out);
        out.flush();

      } else { // Otherwise, send the constrained DDS
        // Instantiate the CEEvaluator and parse the constraint expression
        CEEvaluator ce = new CEEvaluator(myDDS);
        ce.parseConstraint(rs);

        // Send the constrained DDS back to the client
        PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
        myDDS.printConstrained(pw);
        pw.flush();
      }

    } finally { // release lock if needed
      if (ds != null) ds.release();
    }
  }
 private boolean write(String message) {
   if (socket != null) {
     p.println(message);
     p.flush();
   }
   return true;
 }
Beispiel #13
0
  public static void main(String[] args) throws IOException {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);
    int T = parseInt(br.readLine());
    for (int t = 0; t < T; t++) {
      int N = parseInt(br.readLine());
      int[] C = new int[26];
      for (int i = 0; i < N; i++) {
        String str = br.readLine();
        int s = str.charAt(0) - 'a';
        int e = str.charAt(str.length() - 1) - 'a';
        C[s]++;
        C[e]--;
      }
      int s = 0, e = 0;
      for (int i = 0; i < 26; i++) {
        if (C[i] > 0) s += C[i];
        if (C[i] < 0) e += C[i];
      }
      boolean valid = (s == 1) && (e == -1);
      if (!valid) out.printf("The door cannot be opened.\n");
      else out.printf("Ordering is possible.\n");
    }
    out.flush();
    out.close();
    br.close();
  }
 public String getAnswers(List<IN> l, OutputStyle outputStyle, boolean preserveSpacing) {
   StringWriter sw = new StringWriter();
   PrintWriter pw = new PrintWriter(sw);
   printAnswers(l, pw, outputStyle, preserveSpacing);
   pw.flush();
   return sw.toString();
 }
Beispiel #15
0
	public static void main(String[] args) throws IOException {
		int ttt = nextInt();
		for (int test = 1; test <= ttt; test++) {
			str = " " + next();
			n = str.length() - 1;

			int dp[][] = new int[n + 1][n + 1];
			for (int i = 1; i <= n; i++)
				dp[i][i] = 1;

			for (int len = 1; len <= n; len++)
				for (int l = 1; l + len <= n; l++) {
					int r = l + len;
					dp[l][r] = (dp[l][r - 1] + dp[l + 1][r] - dp[l + 1][r - 1])
							% mod;
					if (str.charAt(l) == str.charAt(r)) {
						dp[l][r]++;
						if (l + 1 <= r - 1)
							dp[l][r] = (dp[l][r] + dp[l + 1][r - 1]) % mod;
					}
				}

			out.println("Case " + test + ": " + (dp[1][n] + mod) % mod);
		}

		out.flush();
		out.close();
	}
Beispiel #16
0
 public static void dumptg(ThreadGroup tg, PrintWriter out) {
   if (tg == null) {
     tg = Thread.currentThread().getThreadGroup();
     while (tg.getParent() != null) tg = tg.getParent();
   }
   dumptg(tg, out, 0);
   out.flush();
 }
  public static void main(String[] args) throws IOException {
    Scanner in = new Scanner(new File("System.in"));
    PrintWriter out = new PrintWriter(new File("System.out"));
    List<Stack<String>> order = new ArrayList<Stack<String>>();
    int N = in.nextInt();

    out.flush();
  }
  @Override
  public void run() {
    List<Queen> queens = readData();

    boolean res = solve(queens);

    out.print(res ? "NO" : "YES");
    out.flush();
  }
Beispiel #19
0
  public void send(String s) throws IOException {
    if (s != null) {
      out.println(s);
      out.flush();
    }

    if ((line = in.readLine()) != null) // output the response
    System.out.println(line);
  }
 // Adds the message to the file
 public void addMessage(String username, String message) {
   // System.out.println("MESSAGE ADDED TO FILE");
   // Checks if the user is one of the 2 users
   if (username == user1 || username == user2) {
     // Writes the message to the file
     output.println(username + " " + message);
     output.flush();
   } else throw new IllegalArgumentException("Invalid Username");
 }
Beispiel #21
0
 public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   PrintWriter pw = new PrintWriter(System.out);
   while (sc.hasNextInt()) {
     solve(sc, pw);
   }
   sc.close();
   pw.flush();
   pw.close();
 }
Beispiel #22
0
 /**
  * ** Encodes the specified DBRecordKyes into XML and writes it to ** a specified PrintWriter
  * ** @param out The PrintWriter ** @param dbrk The list of DBRecordKeys
  */
 public static void printXML(PrintWriter out, DBRecordKey... dbrk) {
   if (out != null) {
     out.write("<" + DBFactory.TAG_RecordKeys + ">\n");
     for (int i = 0; i < dbrk.length; i++) {
       dbrk[i].printXML(out, 4);
     }
     out.write("</" + DBFactory.TAG_RecordKeys + ">\n");
     out.flush();
   }
 }
Beispiel #23
0
	public static void main(String[] args) throws IOException {

		loop: while (scan.hasNext()) {
			str = scan.next();
			len = str.length();
			int one = 0, two = 0, three = 0, four = 0, five = 0, six = 0, sum = 0;
			for (int i = 0; i < len; i++) {
				ch = str.charAt(i) - '0';
				sum += ch;
				if (ch == 1)
					one++;
				else if (ch == 2)
					two++;
				else if (ch == 3)
					three++;
				else if (ch == 4)
					four++;
				else if (ch == 5)
					five++;
				else
					six++;

				if (sum > 31) {
					if ((i & 1) == 1)
						out.println(str + " A");
					else
						out.println(str + " B");
					continue loop;
				}
			}
			for (int i = 0; i <= 31; i++)
				for (int onei = 0; onei <= 4; onei++)
					for (int twoi = 0; twoi <= 4; twoi++)
						for (int threei = 0; threei <= 4; threei++)
							for (int fouri = 0; fouri <= 4; fouri++)
								for (int fivei = 0; fivei <= 4; fivei++)
									for (int sixi = 0; sixi <= 4; sixi++)
										dp[i][onei][twoi][threei][fouri][fivei][sixi] = -1;
			dfs(sum, one, two, three, four, five, six);
			if (dp[sum][one][two][three][four][five][six] == 0) {
				if ((len & 1) == 1)
					out.println(str + " A");
				else
					out.println(str + " B");
			} else {
				if ((len & 1) == 0)
					out.println(str + " A");
				else
					out.println(str + " B");
			}
		}

		out.flush();
		out.close();
	}
Beispiel #24
0
  public void doGetHELP(ReqState rs) throws Exception {
    HttpServletResponse response = rs.getResponse();

    response.setContentType("text/html");
    response.setHeader("XDODS-Server", getServerVersion());
    response.setHeader("Content-Description", "dods-help");

    PrintWriter pw = new PrintWriter(new OutputStreamWriter(response.getOutputStream()));
    printHelpPage(pw);
    pw.flush();
  }
Beispiel #25
0
  public static void main(String[] args) throws Exception {
    long start = System.currentTimeMillis();

    solve();
    out.flush();

    long end = System.currentTimeMillis();
    // trace(end-start + "ms");
    br.close();
    out.close();
  }
Beispiel #26
0
  public static void main(String[] args) {
    long start = System.currentTimeMillis();

    while (in.hasNext()) solve();
    out.flush();

    long end = System.currentTimeMillis();
    // trace(end-start + "ms");
    in.close();
    out.close();
  }
Beispiel #27
0
  // メッセージをサーバーに送信する
  public void sendMessage(String msg) {
    try {
      OutputStream output = socket.getOutputStream();
      PrintWriter writer = new PrintWriter(output);

      writer.println(msg);
      writer.flush();
    } catch (Exception err) {
      msgTextArea.append("ERROR>" + err + "\n");
    }
  }
Beispiel #28
0
  public static void main(String[] args) {
    debug = args.length > 0;
    long start = System.currentTimeMillis();

    solve();
    out.flush();

    long end = System.currentTimeMillis();
    dump((end - start) + "ms");
    in.close();
    out.close();
  }
Beispiel #29
0
  public void doGetVER(ReqState rs) throws Exception {
    HttpServletResponse response = rs.getResponse();

    response.setContentType("text/plain");
    response.setHeader("XDODS-Server", getServerVersion());
    response.setHeader("Content-Description", "dods-version");

    PrintWriter pw = new PrintWriter(new OutputStreamWriter(response.getOutputStream()));

    pw.println("Server Version: " + getServerVersion());
    pw.flush();
  }
Beispiel #30
0
  public static void main(String[] args) {
    debug = args.length > 0;
    long start = System.nanoTime();

    solve();
    out.flush();

    long end = System.nanoTime();
    dump((end - start) / 1000000 + " ms");
    in.close();
    out.close();
  }