Loading...

パイプをつなげる

pojの1146にチャレンジしていて、手で入力するのが面倒になったので、標準出力、標準入力を他のストリームにつなげて、自動化を試みた。
テスト結果を判定するまでにはいたってない
Orz...

package p1146;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;

//abaacb
//cbbaa
//a
//cab
//abcd
//acbb
//azyxwvutsrqpppooonnnmmmlllkkkjjjiiihhhgfedcccbbaaa

//ababac
//No Successor
//No Successor
//cba
//abdc
//babc
//baaaabcccdefghhhiiijjjkkklllmmmnnnooopppqrstuvwxyz
public class TestMain {

public static void main(String[] args) throws IOException {
PipedOutputStream outputStream = new PipedOutputStream();
PipedInputStream inputStream = new PipedInputStream();

outputStream.connect(inputStream);
System.setIn(inputStream);

PipedOutputStream outputStream2 = new PipedOutputStream();
PipedInputStream inputStream2 = new PipedInputStream();
inputStream2.connect(outputStream2);
System.setOut(new PrintStream(outputStream2));

Thread thread = new Thread(new Runnable() {

public void run() {
try {
Main.main(null);
} catch (IOException e) {
e.printStackTrace();
}

}
});

thread.start();
String[] ss = { "abaacb", "cbbaa", "a", "cab", "abcd", "acbb¥n",
"azyxwvutsrqpppooonnnmmmlllkkkjjjiiihhhgfedcccbbaaa", };

BufferedReader reader = new BufferedReader(new InputStreamReader(
inputStream2));
PrintWriter writer = new PrintWriter(outputStream);

for (String s : ss) {
write(writer, s);
System.err.println(reader.readLine());
}

write(writer, "#");
// System.out.println("OK");

}

static void write(PrintWriter writer, String s){
writer.write(s + "¥n");
writer.flush();
}

}
リアクション: 
java 7798191916428528705

コメントを投稿

ホーム item

このブログを検索

Random Posts

Popular Posts

Labels

ADS