Skip to content

Instantly share code, notes, and snippets.

@kitayuta
Created November 1, 2014 10:51
Show Gist options
  • Save kitayuta/7a8b258c277aff268e5e to your computer and use it in GitHub Desktop.
Save kitayuta/7a8b258c277aff268e5e to your computer and use it in GitHub Desktop.
#include <string>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <unistd.h>
using namespace std;
const string token="yazawa",base="http://not-522.appspot.com/coderunner/";
string query(string url) {
FILE *f = popen(("curl -s \"" + url + "\"").c_str(), "r");
if (f == NULL) {
perror("error!");
}
char buf[1024];
string res;
while (!feof(f)) {
if (fgets(buf, 1024, f) == NULL) break;
res += (string)(buf);
}
pclose(f);
return res;
}
int newgame(){
return stoi(query(base+"new"+"?token="+token));
}
string get(int n){
return query(base+"get"+"?token="+token+"&stones="+to_string(n));
}
int main() {
int N=newgame(),now;
for(;;){
if(N%4==0) now=1;
else now=N%4;
cout<<N<<" "<<now<<endl;
string res=get(now);
if(res=="YOU WIN"||res=="YOU LOSE"){
cout<<res<<endl;
break;
}else N=stoi(res);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment