可能是jdk版本问题,SWUST上面的没有skipNbytes();这个方法。错了一百遍。。。。。,虽然有这个题用这个跳过\r\n也是错的,因为第二行还有其他的空白符且在要被搜索的字符之前
用bufferedinputStream的话它是一次性将所有输入读入缓冲区,虽然还不知道缓冲区是个啥,
** No enclosing instance of type Main is accessible. Must qualify the allocation with an enclosing instance of type Main (e.g. x.new A() where x is an instance of Main).这句话是提示内部类要在外部类的main里面使用内部类要定义成static,因为静态方法不可以直接调用动态方法 **

import java.io.BufferedInputStream;
import java.io.IOException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
BufferedInputStream in = new BufferedInputStream(System.in);
// char c = (char) in.read();
// node t = new node(c);
node t = new node().creattree(in);
//in.skipNBytes(2L);
// in.close();
char c = (char) in.read();
while(c==' '||c=='\n'||c=='\r') c = (char) in.read();
t.find(t, c);
}
public static class node {
char ch;
node R, L;
node(char ch) {
super();
this.ch = ch;
}
node() {
}
public void find(node t, char c) {
if (t == null)
return;
if (t.ch == c) {
if (t.L == null)
System.out.print("L:#");
else
System.out.print("L:" + t.L.ch);
if (t.R == null)
System.out.print(",R:#");
else
System.out.print(",R:" + t.R.ch);
return;
}
find(t.L, c);
find(t.R, c);
}
public node creattree(BufferedInputStream in) throws IOException {
char c = (char) in.read();
node t;
if (c == '#') {
return t = null;
} else {
t = new node(c);
}
t.L = creattree(in);
t.R = creattree(in);
return t;
}
}
}

本文探讨了Java中使用BufferedInputStream跳过特定字节的问题,以及内部类在不同上下文中访问的限制。面对SWUST平台上的挑战,文章深入分析了skipNbytes方法的缺失及替代方案,并解释了No enclosing instance of type Main is accessible错误的原因与解决办法。
891

被折叠的 条评论
为什么被折叠?



