这是 Perl 中的数据生成器脚本;它在每一行上生成 2 次,第二次总是晚于第一次:
#!/usr/bin/env perl
use strict;
use warnings;
foreach my $i (1..239)
{
my $h1 = 10 + rand 8;
my $h2 = $h1 + 1;
my $m1 = rand 60;
my $m2 = rand 60;
printf "%.2d:%.2d,%.2d:%.2d\n", $h1, $m1, $h2, $m2;
}
这是一个适度冗长的 C++ 程序,它对 Perl 生成的数据文件进行排序,其方式与 Unixsort
程序相同。
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
std::vector<std::string> input;
std::string line;
while (std::getline(std::cin, line))
input.push_back(line);
std::sort(input.begin(), input.end());
//C++03
//for (std::vector<std::string>::iterator it = input.begin(); it != input.end(); ++it)
// std::cout << *it << std::endl;
//C++11
for (auto &it : input)
std::cout << it << std::endl;
}
可能有压缩 C++ 的方法,但它适用于我(Mac OS X 10.8.3 上的 G++ 4.7.1):
g++ -O3 -g -std=c++11 -Wall -Wextra rs.cpp -o rs
肯定有压缩 Perl 代码的方法。