Created
November 2, 2014 14:58
-
-
Save nahcnuj/75022059cf0d4da22353 to your computer and use it in GitHub Desktop.
CODE RUNNER 予選 B のコードです(とても汚い). 一応, トークンは伏せました.
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 <string> | |
#include <iostream> | |
#include <cstdio> | |
#include <cstdlib> | |
#include <vector> | |
#include <utility> | |
#include <algorithm> | |
#include <sstream> | |
#include <ctime> | |
#include <windows.h> | |
using namespace std; | |
const string TOKEN = "xxxx"; | |
typedef pair<int,int> P; | |
string query(string url); | |
bool compare(const P& a, const P& b) { return a.second > b.second; } | |
vector<P> skill(100); | |
string attack(string a) { | |
return "https://game.coderunner.jp/attack?skill=" + a + "&token=" + TOKEN; | |
} | |
string info() { | |
return "https://game.coderunner.jp/info?filter=history&style=text&token=" + TOKEN; | |
} | |
void reload() { | |
for (int i = 0; i < 100; ++i) { | |
stringstream ss; | |
ss << i; | |
string res = query(attack(ss.str())); | |
cerr << "#" << i << ":" << res << endl; | |
skill[i].second = atoi( res.c_str() ); | |
} | |
} | |
P getInfo() { | |
stringstream ss(query(info())); | |
istringstream iss(ss.str()); | |
string row, next = ss.str(); | |
vector<P> data; | |
while (getline(iss,row)) { | |
stringstream r; | |
r << row; | |
int id, sid, atk; | |
r >> id >> sid >> atk; | |
cerr << " " << id << " " << sid << " " << atk << endl; | |
data.push_back( make_pair(sid,atk) ); | |
iss.ignore(16,'\r'); | |
iss.ignore(16,'\n'); | |
} | |
if (data.empty()) return make_pair(0,-1); | |
sort(data.begin(),data.end(),compare); | |
for (int i = 0; i < data.size() && i < 3; ++i) | |
return data.front(); | |
} | |
int main() { | |
srand((unsigned)time(NULL)); | |
while (true) { | |
P x = getInfo(); | |
stringstream ss; | |
int t; | |
if (rand()%100 > (x.second > 1500 ? 10 : 90)) { | |
t = x.first; | |
} | |
else { | |
t = rand()%100; | |
} | |
ss << t; | |
int res = atoi( query(attack(ss.str())).c_str() ); | |
cerr << t << ":" << res << endl; | |
} | |
return 0; | |
} | |
string query(string url) { | |
Sleep(1000); | |
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment