Skip to content

Instantly share code, notes, and snippets.

@rebornplusplus
Created October 31, 2020 22:41
Show Gist options
  • Save rebornplusplus/aeec12b641403d8e8a4e4305738b7bcc to your computer and use it in GitHub Desktop.
Save rebornplusplus/aeec12b641403d8e8a4e4305738b7bcc to your computer and use it in GitHub Desktop.
Interactive stuffs
#include <bits/stdc++.h>
using namespace std;
void read(int& x, int& y) {
cin >> x >> y;
cerr << "cc< " << x << " " << y << endl;
}
void write(int x, int y) {
cout << x << " " << y << endl;
cerr << "cc> " << x << " " << y << endl;
}
int main(int argc, char** argv) {
int x = 2, y = 4;
while(x < 10) {
write(x, y);
read(x, y);
++x;
}
return 0;
}
#!/usr/bin/python3
import sys
def read():
x, y = map(int, input().split())
sys.stderr.write("py< {} {}\n".format(x, y))
sys.stderr.flush()
return [ x, y ]
def write(x, y):
print("{} {}".format(x, y))
sys.stdout.flush()
sys.stderr.write("py> {} {}\n".format(x, y))
sys.stderr.flush()
while True:
x, y = read()
y += 1
write(x, y)
g++ -o cpp cpp.cc
mkfifo fifo
# ./cpp <fifo | tee >(./py.py | tee fifo)
./cpp <fifo | ./py.py >fifo
rm fifo cpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment