Skip to content

Instantly share code, notes, and snippets.

@seungwon0
Last active December 15, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seungwon0/5184669 to your computer and use it in GitHub Desktop.
Save seungwon0/5184669 to your computer and use it in GitHub Desktop.
downloads sample input/output data from acmicpc.net
#!/usr/bin/env perl
#
# get-input-output.pl - downloads sample input/output data from acmicpc.net
#
# Downloads sample input/output data from Baekjoon Online Judge (acmicpc.net).
#
# Seungwon Jeong <seungwon0@gmail.com>
#
# Copyright (C) 2013 by Seungwon Jeong
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
use perl5i::2;
use IO::All;
if ( @ARGV != 1 ) {
say "Usage: $PROGRAM_NAME PROBLEM_NUMBER";
exit 2;
}
my $problem_number = $ARGV[0];
$problem_number =~ tr/0-9//cd;
my $base_url = 'http://www.acmicpc.net/problem/';
my $document < io $base_url . $problem_number;
my $pattern = qr{<div [ ] class [ ] = [ ] "sampledata" > ( .*? ) </div>}xms;
my ( $input, $output ) = $document =~ /$pattern/g;
# Use Unix new line
$input =~ s/\r\n/\n/g;
$output =~ s/\r\n/\n/g;
$input > io 'input';
$output > io 'output';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment