public static void main(String[] args) throws Exception { /* BufferedReader br=new BufferedReader(new FileReader("input.txt")); BufferedWriter out=new BufferedWriter(new FileWriter("output.txt")); */ BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 2000); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out), 2000); String[] s = br.readLine().split(" "); int n = Integer.parseInt(s[0]); int q = Integer.parseInt(s[1]); int num[] = new int[n + 1]; int[] m = new int[3 * n + 1]; // size = 2*n+1 Arrays.fill(num, -1); s = br.readLine().split(" "); for (int i = 1; i <= n; i++) num[i] = Integer.parseInt(s[i - 1]); /// build tree maketree(1, 1, n, m, num); for (int qq = 1; qq <= q; qq++) { s = br.readLine().split(" "); int i = Integer.parseInt(s[0]); int j = Integer.parseInt(s[1]); int ans = query(1, 1, n, m, num, i, j); out.write("" + num[ans] + "\n"); out.flush(); } }
public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); // byte digit[]=new byte[101]; // boolean[] check=new boolean[101]; // int num[]=new int[99999]; ans = 0; int tests = Integer.parseInt(br.readLine()); BigInteger f[] = new BigInteger[101]; for (int i = 1; i <= 100; i++) { f[i] = new BigInteger(("" + i)); } for (int i = 2; i <= 100; i++) { f[i] = f[i].multiply(f[i - 1]); } for (int i = 0; i < tests; i++) { int n = Integer.parseInt(br.readLine()); out.write("\n" + f[n].toString()); out.flush(); } }
public static void makeTextFile(String fwrite) throws IOException { BufferedWriter writer = new BufferedWriter(new FileWriter(fwrite)); int i, j; for (i = 65; i < 65 + FILESIZE; i++) { for (j = 0; j < PACKET_SIZE; j++) { writer.write((char) i); } } writer.close(); }
public static void main(String[] args) throws IOException { int num = 0; int guess = -1; int answer; String name; String line; String result; String scorefile = "highscores_java"; BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); System.out.println("guess.java - Guess a number between 1 and 100\n"); // generate random number java.util.Random generator = new java.util.Random(System.currentTimeMillis()); answer = generator.nextInt() / 42949673 + 50; // play game while (guess != answer) { num++; System.out.print("Enter guess " + num + ": "); result = stdin.readLine(); guess = Integer.parseInt(result); if (guess < answer) { System.out.println("Higher..."); } else if (guess > answer) { System.out.println("Lower..."); } } System.out.println("Correct! That took " + num + " guesses.\n"); // save high score System.out.print("Please enter your name: "); name = stdin.readLine(); try { BufferedWriter outfile = new BufferedWriter(new FileWriter(scorefile, true)); outfile.write(name + " " + num + "\n"); outfile.close(); } catch (IOException exception) { System.out.println("ERROR: Can't read from " + scorefile + "\n"); } // print high scores try { BufferedReader infile = new BufferedReader(new FileReader(scorefile)); while ((line = infile.readLine()) != null) { System.out.println(line); } infile.close(); } catch (IOException exception) { System.out.println("ERROR: Can't read from " + scorefile + "\n"); } }
public boolean test() { ExtendedService es = null; boolean ok = true; String tmpfilename = getParameter("tmpfile"); try { // Lookup the javax.jnlp.ExtendedService object es = (ExtendedService) ServiceManager.lookup("javax.jnlp.ExtendedService"); } catch (UnavailableServiceException ue) { System.out.println(ue); ue.printStackTrace(); // Service is not supported ok = false; } if (!ok) return false; // Open a specific file in the local machine File tmpfile = new File(tmpfilename); // Java Web Start will pop up a dialog asking the user to grant permission // to read/write the file 'tempfile' try { FileContents fc_tmpfile = es.openFile(tmpfile); if (!tmpfilename.equals(fc_tmpfile.getName())) { System.out.println( "\t tmpfile(out): " + tmpfilename + ", unequal to fc-filename: " + fc_tmpfile.getName() + " - info"); // ok=false; // return ok; } if (!fc_tmpfile.canWrite()) { System.out.println( "\t outfile: " + tmpfilename + ", no write access (may not exist yet) - info"); } // You can now use the FileContents object to read/write the file java.io.OutputStream sout = fc_tmpfile.getOutputStream(true); BufferedWriter bwsout = new BufferedWriter(new OutputStreamWriter(sout)); bwsout.write(datum, 0, datum.length()); bwsout.flush(); bwsout.close(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); System.out.println("\t Error while IO write - failed"); ok = false; return ok; } // read back .. try { FileContents fc_tmpfile = es.openFile(tmpfile); if (!tmpfilename.equals(fc_tmpfile.getName())) { System.out.println( "\t tmpfile(in): " + tmpfilename + ", unequal to fc-filename: " + fc_tmpfile.getName() + " - info"); // ok=false; // return ok; } if (!fc_tmpfile.canRead()) { System.out.println("\t outfile: " + tmpfilename + ", read access failed"); ok = false; } // You can now use the FileContents object to read/write the file java.io.InputStream sin = fc_tmpfile.getInputStream(); BufferedReader brsin = new BufferedReader(new InputStreamReader(sin)); String in = brsin.readLine(); if (!in.equals(datum)) { System.out.println("\t file content <" + in + "> does not match <" + datum + "> - failed"); ok = false; } brsin.close(); } catch (Exception e) { System.out.println(e); e.printStackTrace(); System.out.println("\t Error while IO read - failed"); ok = false; return ok; } return ok; }