Last active
December 8, 2018 03:39
-
-
Save TrungNguyen1909/6990c06892825e863987646f24b054f8 to your computer and use it in GitHub Desktop.
Communication/Interactive checker for CMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
#include <sys/stat.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <signal.h> | |
using namespace std; | |
void handler(int signum){ | |
cout<<0; | |
cerr<<"Idleness limit Exceeded!"; | |
exit(0); | |
} | |
int main(int argc, char* argv[]){ | |
signal(SIGALRM,handler); | |
alarm(1); | |
auto fi = fdopen(open(argv[1],O_RDWR),"r"); | |
auto fo = fdopen(open(argv[2],O_RDWR),"w"); | |
setvbuf(fi, 0LL, 2, 0LL); | |
setvbuf(fo, 0LL, 2, 0LL); | |
int h,n; | |
cin>>h>>n; | |
fprintf(fo,"%d\n",h); | |
int cnt=log2(h)+2; | |
while(cnt--){ | |
int q; | |
fscanf(fi,"%d",&q); | |
if(q<=0){ | |
cout<<0; | |
cerr<<"Invalid query!"; | |
exit(0); | |
} | |
if(q>n) { | |
fprintf(fo,"H\n"); | |
} | |
else if(q<n){ | |
fprintf(fo,"L\n"); | |
} | |
else{ | |
cout<<1; | |
cerr<<"okok! Correct number."; | |
exit(0); | |
} | |
} | |
cout<<0; | |
cerr<<"You guessed too much!"; | |
exit(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment