Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. import java.io.*;
  2. import java.util.Arrays;
  3. public class MyScanner {
  4. private Reader in = null;
  5. private int cur;
  6. public MyScanner(InputStream in) throws IOException {
  7. this.in = new BufferedReader(
  8. new InputStreamReader(
  9. in,
  10. "utf-8"
  11. ),
  12. 1024
  13. );
  14. this.cur = this.in.read();
  15. }
  16. public MyScanner(Reader in) throws IOException {
  17. this.in = in;
  18. this.cur = this.in.read();
  19. }
  20. public MyScanner(String str) throws IOException {
  21. this.in = new StringReader(str);
  22. this.cur = this.in.read();
  23. }
  24. public void close() {
  25. try {
  26. in.close();
  27. } catch (IOException e) {
  28. System.out.println("Error output" + e.getMessage());
  29. }
  30. }
  31. public String nextLine() throws IOException {
  32. StringBuilder buffer = new StringBuilder();
  33. //buffer.append(" ");
  34. while (getCurrent() != '\n' && !isEOF()) {
  35. buffer.append(getCurrent());
  36. skip();
  37. }
  38. skip();
  39. //skip();
  40. return new String(buffer);
  41. }
  42. public boolean hasNextLine() throws IOException {
  43. return !isEOF();
  44. }
  45. public void skip() throws IOException {
  46. cur = in.read();
  47. }
  48. public boolean isEOF() {
  49. return cur == -1;
  50. }
  51. public char getCurrent() {
  52. return (char) cur;
  53. }
  54. public boolean hasNextInt() throws IOException {
  55. while(getCurrent() != '\n' && !isEOF()) {
  56. if (Character.isDigit(getCurrent()) || getCurrent() == '-')
  57. return true;
  58. skip();
  59. }
  60. return false;
  61. }
  62. public int nextInt() throws IOException {
  63. StringBuilder buffer = new StringBuilder();
  64. while (Character.isDigit(getCurrent()) || getCurrent() == '-') {
  65. buffer.append(getCurrent());
  66. skip();
  67. }
  68. skip();
  69. return Integer.parseInt(buffer.toString());
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement