Google APAC----Africa 2010, Qualification Round(Problem B. Reverse Words)----Perl 解法
原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p1
问题描述:
Problem Given a list of space separated words, reverse the order of the words. Each line of text contains L letters and W words. A line will only consist of letters and space characters. There will be exactly one space character between each pair of consecutive words. Input The first line of input gives the number of cases, N.
N test cases follow. For each test case there will a line of letters and space characters indicating a list of space separated words. Spaces will not appear at the start or end of a line. Output For each test case, output one line containing "Case #x: " followed by the list of words in reverse order. Limits Small dataset N =
≤ L ≤ Large dataset N =
≤ L ≤
Sample:
Input this is a test
foobar
all your base Output
Case #1: test a is this
Case #2: foobar
Case #3: base your all
Perl算法:
#!/usr/bin/perl
my $infile='B-large-practice.in';
my $outfile='B-large-out.out';
open my $in,'<',$infile
or die "Cannot open $infile:$!\n";
open my $out,'>',$outfile
or die "Cannot open $outfile:$!\n"; chomp(my $N=<$in>);
my $line;
my @res;
for(my $i=;$i<=$N;$i++){
chomp($line=<$in>);
@res=split " ",$line; #将一行的字符串分隔开来,以便于利用 reverse 函数进行翻转
@res=reverse @res;
print $out "Case #$i: @res\n"; }
close $in;
close $out;
上传原题地址链接网站,结果正确
Google APAC----Africa 2010, Qualification Round(Problem B. Reverse Words)----Perl 解法的更多相关文章
- Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words
Google Code Jam Africa 2010 Qualification Round Problem B. Reverse Words https://code.google.com/cod ...
- Google APAC----Africa 2010, Qualification Round(Problem C. T9 Spelling)----Perl 解法
原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p2 问题描述: Problem The Latin alphabe ...
- Google APAC----Africa 2010, Qualification Round(Problem A. Store Credit)----Perl 解法
原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p0 问题描述: Problem You receive a cre ...
- Google Code Jam Africa 2010 Qualification Round Problem A. Store Credit
Google Code Jam Qualification Round Africa 2010 Problem A. Store Credit https://code.google.com/code ...
- Google Code Jam 2009 Qualification Round Problem C. Welcome to Code Jam
本题的 Large dataset 本人尚未解决. https://code.google.com/codejam/contest/90101/dashboard#s=p2 Problem So yo ...
- Google Code Jam 2009 Qualification Round Problem B. Watersheds
https://code.google.com/codejam/contest/90101/dashboard#s=p1 Problem Geologists sometimes divide an ...
- Google Code Jam 2009 Qualification Round Problem A. Alien Language
https://code.google.com/codejam/contest/90101/dashboard#s=p0 Problem After years of study, scientist ...
- [C++]Infinite House of Pancakes——Google Code Jam 2015 Qualification Round
Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...
- [C++]Standing Ovation——Google Code Jam 2015 Qualification Round
Problem It’s opening night at the opera, and your friend is the prima donna (the lead female singer) ...
随机推荐
- Redis实现分布式存储Session
前言: 在单个项目时,一般都是用HttpSession接口存储当前登录用户的信息.但是在分布式项目的情况下,session是不会共享的,那怎么实现session共享呢?往下看.... 一.准备工作(基 ...
- 关于 unsigned long long 于 long long
long long 最大只有19位 : unsigned long long 最大有20位 ,原因牺牲了符合位来换取更大的记录
- 16个最佳响应式HTML5框架分享
HTML5框架可以快速构建响应式网站,它们帮助程序员减少编码工作,减少冗余的代码.如今有很多免费的HTML5框架可供使用,由于它们有着响应式设计.跨浏览器兼容.相对轻量级等特点,这些框架在开发中都十分 ...
- rocksDB vs InnoDB vsTokuDB
原文地址 https://minervadb.com/index.php/2018/08/06/comparing-tokudb-rocksdb-and-innodb-performance-on-i ...
- linux下的ps命令
ps命令用于报告当前系统的进程状态.可以搭配kill指令随时中断.删除不必要的程序.ps命令是最基本同时也是非常强大的进程查看命令,使用该命令可以确定有哪些进程正在运行和运行的状态.进程是否结束.进程 ...
- Steps to install Docker on Manjaro 16.10--转
https://manjaro-tutorial.blogspot.com/2016/12/how-to-install-docker-on-manjaro-1610.html Open Termin ...
- GANS--理解
GAN所建立的一个学习框架,实际上就是生成模型和判别模型之间的一个模仿游戏.生成模型的目的,就是要尽量去模仿.建模和学习真实数据的分布规律:而判别模型则是要判别自己所得到的一个输入数据,究竟是来自于真 ...
- hadoop ——HDFS存储
一.HDFS概念 二.HDFS优缺点 三.HDFS如何存储 一.HDFS概念 HDFS(Hadoop Distributed File System)是Hadoop项目的核心子项目,是分布式计算中数据 ...
- Linux防火墙简介 – iptables配置策略
Linux防火墙简介 – iptables配置策略 Netfilter/iptables简介 要想真正掌握Linux防火墙体系,首先要搞清楚Netfilter和iptables的关系,Netfilte ...
- mongodb-脏数据问题
采用多线程后, 发现最大的问题是redis和mongodb的脏数据问题 1, upsert 的脏数据问题 多线程对同一个collect进行upsert操作时, 会引发并发脏数据问题, 最开始的解决方案 ...