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 ...
随机推荐
- [Network]Wireless and Mobile
Wireless 1 Introduction 1.1 Elements 1. Wireless Hosts Wireless does not mean mobility. 2. Base Stat ...
- Unigine 基础入门
1. 首先要搭建好开发环境: 1)Visual Stodio 已经安装了. 2). Microsoft Windows SDK 7.1 (for Windows 7): https://www.mic ...
- Python的经典问题——中文乱码
关键字:Python UTF-8 GBK 中文 乱码 估计入门时都会遇到的.我是在windows下用的Python25自带的IDLE编辑运行的,发现运行脚本得出的结果有一些中文显示是乱码,但有一些是正 ...
- uva 11355(极角计算)
传送门:Cool Points 题意:给一个圆心为原点的圆和一些线段,问所有线段两端点与圆心连线构成的角度总和占总360度的百分比. 分析:首先将所有线段的两端点变成极角,然后排序(范围[-PI,PI ...
- VSTO学习笔记(十四)Excel数据透视表与PowerPivot
原文:VSTO学习笔记(十四)Excel数据透视表与PowerPivot 近期公司内部在做一种通用查询报表,方便人力资源分析.统计数据.由于之前公司系统中有一个类似的查询使用Excel数据透视表完成的 ...
- selenium webdriver缺陷
关闭 selenium webdriver缺陷 除了http://573301735.com/?p=5126讲 的,昨天又发现一个让我1个小时生不如死的问题,就是使用两个不同的配置文件来初始化dri ...
- dell服务器各类raid 和磁盘在阵列卡上的实验
听很多人说,做好阵列的硬盘从阵列上移除后,重新从硬盘导入阵列信息的时候不能打乱位置,昨天用两台Dell R710,四块sas 300G HP硬盘做实验,实验步骤如下: 一.dell R710首先用三块 ...
- 使用Django创建简易Blog
网上看了个例子,但是自己却运行不同,最后终于知道了原因,记录下来.原来没有给settings.py里的INSTALLED_APPS添加blog.就像这样: 这是一个手把手的实例教程,本来学习笔记一样, ...
- 用css3实现各种图标效果
原文:用css3实现各种图标效果 公共样式 应该说现在绝大多数公司的项目前端都是一团乱,不仅仅是js写的没有任何框架而言,css同样也是如此,导致项目如果要升级或者说有新的变更维护起来就特别困难. 最 ...
- Ubuntu 14.4 使用中遇到的问题汇总
1.java程序字体问题. 基本的原因是openjdk的缘故 下载最新的jdk安装,地址:http://www.oracle.com/technetwork/java/javase/downloads ...