Skip to content

Instantly share code, notes, and snippets.

@linmx0130
Created August 21, 2012 09:15
Show Gist options
  • Select an option

  • Save linmx0130/3413821 to your computer and use it in GitHub Desktop.

Select an option

Save linmx0130/3413821 to your computer and use it in GitHub Desktop.
USACO Data Getter - if the zip file is wrong, this program will help you to get get the data
#include <cstdio>
#include <string>
#define PRONAME "fishing"
char buf[1024];
std::string newfilename;
std::string int2string(int d)
{
std::string ret;
while (d)
{
ret+=d%10+'0';
d/=10;
}
for (int i=0;i<ret.size()>>1;++i)
{
char k=ret[i];
ret[i]=ret[ret.size()-1-i];
ret[ret.size()-1-i]=k;
}
return ret;
}
int main()
{
int nowd=0;
while (1)
{
gets(buf);
if (buf[0]=='\0') continue;
if (buf[0]=='E') break;
if (buf[0]=='I')
{
fclose(stdout);
++nowd;
newfilename=PRONAME;
newfilename+=int2string(nowd);
newfilename+=".in";
freopen(newfilename.c_str(),"w",stdout);
continue;
}
if (buf[0]=='O')
{
fclose(stdout);
newfilename=PRONAME;
newfilename+=int2string(nowd);
newfilename+=".out";
freopen(newfilename.c_str(),"w",stdout);
continue;
}
puts(buf);
}
fclose(stdout);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment