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) ...
随机推荐
- VUE源代码调试方法
前两条出自: https://link.zhihu.com/?target=http%3A//www.orzzone.com/vuejs-project-debug.html https://www. ...
- SpringBoot集成WebSocket【基于STOMP协议】进行点对点[一对一]和广播[一对多]实时推送
原文详细地址,有点对点,还有广播的推送:https://blog.csdn.net/ouyzc/article/details/79884688 下面是自己处理的一些小bug 参考原文demo,结合工 ...
- IDEA Maven Mybatis generator 自动生成代码
IDEA Maven Mybatis generator 自动生成代码 一.安装配置maven以及在Idea中配置maven 安装过程步骤可以看上面的博文,里面介绍得很详细. 二.建数据表 DROP ...
- bash切割文件
split -l 100 ./x01.txt -d -a 3 --additional-suffix=.txt 将 x01.txt文件,-l 100 按照每个100行, -d 以数字累加, -a 3 ...
- bootstrap中对dropdown使用hover代替click
bootstrap的下拉组件需要点击click才能展示下拉列表,这在使用导航的时候很不方便因此有一个扩展的组件来解决这个问题. 在VS的Nuget中查询bootstrap-hover-dropdown ...
- ibatis插入正确但查询不出数据的问题
现在,使用打印的sql在oracle数据库客户端能查询出结果,但执行ibatis查询语句不行,ibatis插入可以. 解决问题的历程: 1. 去掉sql中的where语句,仍然查找不到,确定不是sql ...
- Greenplum表定义
GP中的table和其它关系型数据表是一样的,除了数据被分布在不同的segment以外. 在建表的时候必须申明分布键distribution policy. 建表需定义下面几个方面: 1. 指定列和数 ...
- 小菜读书---《Effective C#:改善C#程序的50种方法》
一.用属性代替可访问的字段 1..NET数据绑定只支持数据绑定,使用属性可以获得数据绑定的好处: 2.在属性的get和set访问器重可使用lock添加多线程的支持. 二.readonly(运行时常量) ...
- GraphQL介绍&使用nestjs构建GraphQL查询服务
GraphQL介绍&使用nestjs构建GraphQL查询服务(文章底部附demo地址) GraphQL一种用为你 API 而生的查询语言.出自于Facebook,GraphQL非常易懂,直接 ...
- 撩课-Java每天5道面试题第9天
撩课Java+系统架构 视频 点击开始学习 76.XML技术的作用? XML技术用于数据存储. 信息配置. 数据交换三方面. 可以将数据存储在XML中, 通过节点. 元素内容. 属性标示数据内容及关系 ...