Skip to content

Instantly share code, notes, and snippets.

@snuke
Created November 1, 2014 16:56
Show Gist options
  • Select an option

  • Save snuke/186d705690faadde033f to your computer and use it in GitHub Desktop.

Select an option

Save snuke/186d705690faadde033f to your computer and use it in GitHub Desktop.
coderunner 2014 予選A
//インクルード・マクロ・定数 略
#define act(...) act2(__VA_ARGS__,"")
string token = "KONOTOKENHANISEMONODESU114514810";
string act2(string com, ...) {
string url = "https://game.coderunner.jp/";
url += com+"?token="+token;
va_list args;
va_start(args, com);
while (1) {
string ns = va_arg(args, char*);
if (ns == "") break;
url += "&"+ns;
}
//cerr << url << endl;
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;
}
char* g(string att, string val) {
static char tmp[105];
att += "="+val;
strcpy(tmp, att.c_str());
return tmp;
}
char* g(string att, int val) {
static char tmp[105];
sprintf(tmp,"%d",val);
att += "="+string(tmp);
strcpy(tmp, att.c_str());
return tmp;
}
int main() {
snuke; // srand macro
string res, s;
rep(i,50) s += string(1,'A'+rand()%4);
res = act("q",g("str",s.c_str()));
int best = atoi(res.c_str());
rep(ti,100000000) {
int r = rand()%8+1;
string p = s;
int l = rand()%(50-r+1);
rep(i,r) s[i+l] = rand()%4+'A';
res = act("q",g("str",s.c_str()));
int x = atoi(res.c_str());
cerr << s << " : " << x << endl;
if (best <= x) best = x; else s = p;
cerr << "now : " << s << " " << best << endl;
sleep(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment