google在线测试练习2
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的更多相关文章
- Google Kickstart在线测试规则以及注意事项
谷歌招聘在如火如荼的进行中,进谷歌都需要经过谷歌kickstart在线测试,然后过了之后还有五轮的面试- -.好吧毕竟你待遇高,你强你有理.. 下面介绍一下进谷歌的第一关google kickstar ...
- hihocoder 在线测试 补提交卡 (Google)
题目1 : 补提交卡 时间限制:2000ms 单点时限:1000ms 内存限制:256MB 描述 小Ho给自己定了一个宏伟的目标:连续100天每天坚持在hihoCoder上提交一个程序.100天过去 ...
- Linux 利用Google Authenticator实现ssh登录双因素认证
1.介绍 双因素认证:双因素身份认证就是通过你所知道再加上你所能拥有的这二个要素组合到一起才能发挥作用的身份认证系统.双因素认证是一种采用时间同步技术的系统,采用了基于时间.事件和密钥三变量而产生的一 ...
- linux上使用google身份验证器(简版)
系统:centos6.6 下载google身份验证包google-authenticator-master(其实只是一个.zip文件,在windwos下解压,然后传进linux) #cd /data/ ...
- Google软件构建工具Bazel原理及使用方法介绍
近期,Google开源了强大的自动化构建工具Bazel. 正好博主近期在使用china版的Bazel--腾讯自主开发的Blade,所以准备跟大家分享一下Google Bazel这个分布式构建系统的原理 ...
- Google Java编程库Guava介绍
本系列想介绍下Java下开源的优秀编程库--Guava[ˈgwɑːvə].它包含了Google在Java项目中使用一些核心库,包含集合(Collections),缓存(Caching),并发编程库(C ...
- 序列化笔记之一:Google的Protocol Buffer格式分析
从公开介绍来看,ProtocolBuffer(PB)是google 的一种数据交换的格式,它独立于语言,独立于平台.作为一个学了多年通信的人,ProtocolBuffer在我看来是一种信源编码.所谓信 ...
- [异常解决] 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 ...
- Google翻译之路
如何将整个网站都翻译成某种语言,想必大家都有碰到这样的问题吧. 如果能够访问Google的话, 那这个太容易不过了. 来看,下面的就是Google提供的直接翻译某个网站. http://transla ...
随机推荐
- 使用FragmentTabhost取代Tabhost
如今Fragment使用越来越广了,尽管Fragment寄生在Activity下.可是它的出现对于开发人员来说是一件很幸运的事,使开发的效率更高效了.好了以下就说说 FragmentTabhos ...
- 做SEO所要具备的四种能力
1,不为失败找借口 既然我们选择了做SEO,那么发生网站被降权.被K是常常的事.当这样的情况发生时,大部分站长首先将责任推给百度机制,由于百度更新算法调整遭降权,不是由于他们的优化没有 ...
- <xliff:g>标签
摘要: 这是Android4.3Mms源代码中的strings.xml的一段代码: <!--Settings item desciption for integer auto-delete sm ...
- Juniper srx防火墙NAT配置
一.基础操作说明: 1. 设备恢复出厂化 root# load factory-default root# set system root-authentication plain-text-pas ...
- ASA虚墙配置
asa配置ASA Version 8.0(2) <system>!hostname ASA5520enable password 2KFQnbNIdI.2KYOU encryptedno ...
- Mars之android的Handler(2)
handler .looper.messageque的关系在前面已经有个介绍,但前面handler(1)中handler的使用是极少的一种情况,因为handler.sendMessage()可以在Ma ...
- OC -- 第一个类
OC -- 第一个类 类名:Car 属性:轮胎个数.时速 行为:跑 完整写一个类:类的声明和实现 1. 类的声明 代码: // NSObject 再Foundation框架中 #import & ...
- hdu1330(递推)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1330 分析:经典问题,n 块相同的木板重叠,最多能够伸出桌面多远 对于n张卡片的最佳摆法,我们只需要在 ...
- poj 1198 hdu 1401 搜索+剪枝 Solitaire
写到一半才发现能够用双向搜索4层来写,但已经不愿意改了,干脆暴搜+剪枝水过去算了. 想到一个非常水的剪枝,h函数为 当前点到终点4个点的最短距离加起来除以2.由于最多一步走2格,然后在HDU上T了, ...
- POJ 2299 Ultra-QuickSort (求序列的逆序对数)
题意:废话了一大堆就是要你去求一个序列冒泡排序所需的交换的次数. 思路:实际上是要你去求一个序列的逆序队数 看案例: 9 1 0 5 4 9后面比它小的的数有4个 1后面有1个 0后面没有 5后面1个 ...