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 = 5

1 ≤ L ≤ 25

Large dataset

N = 100

1 ≤ L ≤ 1000

思路:先一个一个单词反转,再将整个字符串反转。

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main()
{
int n_case;
ifstream ifile("B-large-practice.in");
ofstream ofile("resultb2.txt");
ifile >> n_case;
for(int i = 0; i <= n_case; i++)
{
char line[1002];
ifile.getline(line, 1002);
string words(line);
int begin = 0;
int end = 0;
if(i == 0)
continue;
for(int i = 1; i < words.length(); i++)
{
if(words[i] == ' ')
{
int sum = begin + i - 1;
for(int j = begin; j <= sum / 2; j++)
{
char tmp = words[j];
words[j] = words[sum - j];
words[sum - j] = tmp;
}
begin = i + 1;
}
}
int sum = begin + words.length() - 1;
for(int j = begin; j <= sum / 2; j++)
{
char tmp = words[j];
words[j] = words[sum - j];
words[sum - j] = tmp;
}
sum = words.length() - 1;
for(int j = 0; j <= sum / 2; j++)
{
char tmp = words[j];
words[j] = words[sum - j];
words[sum - j] = tmp;
}
ofile << "Case #" << i << ": " << words << endl;
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

google在线测试练习2的更多相关文章

  1. Google Kickstart在线测试规则以及注意事项

    谷歌招聘在如火如荼的进行中,进谷歌都需要经过谷歌kickstart在线测试,然后过了之后还有五轮的面试- -.好吧毕竟你待遇高,你强你有理.. 下面介绍一下进谷歌的第一关google kickstar ...

  2. hihocoder 在线测试 补提交卡 (Google)

    题目1 : 补提交卡 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho给自己定了一个宏伟的目标:连续100天每天坚持在hihoCoder上提交一个程序.100天过去 ...

  3. Linux 利用Google Authenticator实现ssh登录双因素认证

    1.介绍 双因素认证:双因素身份认证就是通过你所知道再加上你所能拥有的这二个要素组合到一起才能发挥作用的身份认证系统.双因素认证是一种采用时间同步技术的系统,采用了基于时间.事件和密钥三变量而产生的一 ...

  4. linux上使用google身份验证器(简版)

    系统:centos6.6 下载google身份验证包google-authenticator-master(其实只是一个.zip文件,在windwos下解压,然后传进linux) #cd /data/ ...

  5. Google软件构建工具Bazel原理及使用方法介绍

    近期,Google开源了强大的自动化构建工具Bazel. 正好博主近期在使用china版的Bazel--腾讯自主开发的Blade,所以准备跟大家分享一下Google Bazel这个分布式构建系统的原理 ...

  6. Google Java编程库Guava介绍

    本系列想介绍下Java下开源的优秀编程库--Guava[ˈgwɑːvə].它包含了Google在Java项目中使用一些核心库,包含集合(Collections),缓存(Caching),并发编程库(C ...

  7. 序列化笔记之一:Google的Protocol Buffer格式分析

    从公开介绍来看,ProtocolBuffer(PB)是google 的一种数据交换的格式,它独立于语言,独立于平台.作为一个学了多年通信的人,ProtocolBuffer在我看来是一种信源编码.所谓信 ...

  8. [异常解决] How make ubuntu use Google Search

    1.Download the hosts file fromhttps://laod.cn/hosts/2016-google-hosts.html [1] 2.Write a bash shell ...

  9. Google翻译之路

    如何将整个网站都翻译成某种语言,想必大家都有碰到这样的问题吧. 如果能够访问Google的话, 那这个太容易不过了. 来看,下面的就是Google提供的直接翻译某个网站. http://transla ...

随机推荐

  1. UDP 通信

    import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; public ...

  2. hdu 1392(凸包)

    传送门:Surround the Trees 题意:求凸包的周长. 分析:凸包模板题,先按极角排好序后,然后根据叉积正负确定凸包. #include <stdio.h> #include ...

  3. 基于Servlet、JSP、JDBC、MySQL的一个简单的用户注冊模块(附完整源代码)

    近期看老罗视频,做了一个简单的用户注冊系统.用户通过网页(JSP)输入用户名.真名和password,Servlet接收后通过JDBC将信息保存到MySQL中.尽管是个简单的不能再简单的东西,但麻雀虽 ...

  4. 【ThinkingInC++】52、函数内部的静态变量

    /** * 书本:[ThinkingInC++] * 功能:函数内部的静态变量 * 时间:2014年9月17日18:06:33 * 作者:cutter_point */ #include " ...

  5. POj 1879 Tempus et mobilius Time and motion (模拟+群)

    题目特别长,大意为球的传递. 三个轨道,一个库.各自是分钟单位的轨道.5min单位的轨道.一小时单位的轨道.还有就是n容量的库. 每过一分钟,一个小球从库里面出来,库符合先进先出,进入分钟轨道.假设分 ...

  6. JavaWeb 项目中的绝对路径和相对路径以及问题的解决方式

    近期在做JavaWeb项目,总是出现各种的路径错误,并且发现不同情况下 /  所代表的含义不同,导致在调试路径上浪费了大量时间. 在JavaWeb项目中尽量使用绝对路径  由于使用绝对路径是绝对不会出 ...

  7. Storm-0.9.2-incubating源代码编译打包

    近期遇到一些同学询问Storm-0.9.2-incubating源代码编译打包的问题,现将编译步骤说明例如以下: 1.凝视掉project各pom文件里关于maven插件(maven-gpg-plug ...

  8. linux--shell script

    下面是最近学习shell script的一些知识点总结 ***博客园-邦邦酱好***   1.介绍shell是一个文字接口,让我们与系统沟通.shell script就是针对shell所写的脚本.它就 ...

  9. html+css实现登录界面

    <!DOCTYPE html> <style type="text/css"> body{ background-color: #555555; } #ti ...

  10. hdu 1251 字典树模板题 ---多串 查找单词出现次数

    这道题题目里没有给定数据范围 我开了2005  疯狂的WA 然后开了50000, A掉  我以为自己模板理解错  然后一天没吃饭,饿得胃疼还是想着把这题A掉再去吃,谁知竟然是这样的问题,,,呵呵~~~ ...