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. 数据挖掘 决策树算法 ID3 通俗演绎

    决策树是对数据进行分类,以此达到预測的目的.该决策树方法先依据训练集数据形成决策树,假设该树不能对全部对象给出正确的分类,那么选择一些例外添�到训练集数据中,反复该过程一直到形成正确的决策集.决策树代 ...

  2. Java Swing界面编程(31)---菜单条:JMenu

    package com.beyole.test; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMe ...

  3. poj 1220 NUMBER BASE CONVERSION(短除法进制转换)

    题目连接:1220 NUMBER BASE CONVERSION 题目大意:给出两个进制oldBase 和newBase, 以及以oldBase进制存在的数.要求将这个oldBase进制的数转换成ne ...

  4. nagios二次开发(五岁以下儿童)---nagios和nagiosql关系

    基于nagios和nagiosql理解.这将是这两个梳理比较粗糙的简单关系,有关详细信息,请参阅下面的图如:      从上面的关系图中能够看出,nagios与nagiosql共享了主机.主机组.服务 ...

  5. oschina jQuery 插件

    jQuery 插件 jQuery自动完成插件(25) jQuery分页插件(20) jQuery 文件上传(21) jQuery 地图插件(14) jQuery对话框(109) jQuery图片展示/ ...

  6. ON、WHERE、HAVING的差别

    ON .WHERE.HAVING都能通过限制条件筛选数据,但他们的使用及其不同.以下我们来分析三者之间的差别. 1.       ON 和WHERE 全部的查询都回产生一个中间暂时报表,查询结果就是从 ...

  7. Nginx 进程间通信

    Linux下的IPC非常多,nginx的进程都是有亲缘关系的进程,对于他们的通信我们选择TCP socket进行通信.   TCP socket 用来做进程通信的优点有,   1.socket是文件描 ...

  8. hdu2712(贪心)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2712 题意:是求最短的非子串(子串不要求连续)的长度. 分析:把序列划分为尽量多(假设为ans)的含有 ...

  9. Mac下配置Cocos2d-x3.1环境

    一.前期准备 1.ADT:百度下就OK 2.NDK:百度下就OK 3.ANT: http://124.254.47.39/download/55152992/78533365/4/zip/57/132 ...

  10. hibernate得知——Set设置配置

    Set设置配置 创建数据表:表关系的员工有多重身份 create table EMPLOYEE ( id INT NOT NULL auto_increment, first_name VARCHAR ...