题目连接:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1151

题目描述:

For each list of words, output a line with each word reversed without changing the order of the words.

This problem contains multiple test cases!

The first line of a multiple input is an integer N, then a blank line followed
by N input blocks. Each input block is in the format indicated in the problem
description. There is a blank line between input blocks.

The output format consists of N output blocks. There is a blank line between
output blocks.

Input

You will be given a number of test cases. The first line contains a positive
integer indicating the number of cases to follow. Each case is given on a line
containing a list of words separated by one space, and each word contains only
uppercase and lowercase letters.

Output

For each test case, print the output on one line.

Sample Input

1

3
I am happy today
To be or not to be
I want to win the practice contest

Sample Output

I ma yppah yadot
oT eb ro ton ot eb
I tnaw ot niw eht ecitcarp tsetnoc

 /*问题 将一段文字的每个单词反转,但次序不变
解题思路 模拟,具体算法见注释处的坑点*/
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cctype>
#include<string>
#include<algorithm>
using namespace std; int main()
{
int T,t;
char str[],str1[];
string s;
scanf("%d",&T);
while(T--){
scanf("%d",&t);
getchar();
while(t--){
cin.getline(str,); int len=strlen(str);
int i;
for(i=len-;i>=;i--)
if(isalpha(str[i])) break;
str[i+]=' ';
str[i+]='\0'; char *p=NULL;
p=str; while(*p == ' ')
p++; len=strlen(p);
for(i=;i<len;i++){
if(p[i]!=' ')
{
s += p[i];
}
else
{
reverse(s.begin(),s.end());
cout<<s;
if(i != len-) printf(" ");//坑点1
s="";
}
}
cout<<endl;
s="";
}
if(T != ) printf("\n");//坑点2
}
return ;
}

zoj 1151 Word Reversal(字符串操作模拟)的更多相关文章

  1. ZOJ 1151 Word Reversal反转单词 (string字符串处理)

    链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151 For each list of words, output a l ...

  2. ZOJ 1151 Word Reversal

    原题链接 题目大意:给一句话,把每个单词倒序,然后输出. 解法:我是用了一个堆栈,以空格来拆分单词,把每个字母压入堆栈,然后依次输出. 参考代码: /* * 字符串反向,140ms,188kb * 单 ...

  3. zoj1151 zoj1295 Word Reversal 字符串的简单处理

    Word Reversal Time Limit: 2 Seconds      Memory Limit:65536 KB For each list of words, output a line ...

  4. Luogu 1098 - 字符串的展开 - [字符串操作][模拟]

    题目链接:https://www.luogu.org/problemnew/show/P1098 题目描述在初赛普及组的“阅读程序写结果”的问题中,我们曾给出一个字符串展开的例子:如果在输入的字符串中 ...

  5. linux makefile字符串操作函数 替换subst、模式替换patsubst、去首尾空格strip、查找字符串findstring、过滤filter、反过滤filter-out、排序函数sort、取单词word、取单词串wordlist、个数统计words

    1.1       字符操作函数使用 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函 ...

  6. [No000078]Python3 字符串操作

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- '''Python 字符串操作 string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分 ...

  7. Python 字符串操作及string模块使用

    python的字符串操作通过2部分的方法函数基本上就可以解决所有的字符串操作需求: python的字符串属性函数 python的string模块 1.字符串属性方法操作: 1.>字符串格式输出对 ...

  8. c# 字符串操作

    一.字符串操作 //字符串转数组 string mystring="this is a string" char[] mychars=mystring.ToCharArray(); ...

  9. day8(字符串操作)

    一.字符串操作 1.index  #返回字符串的索引值 s = "Hello word" print(s.index('o')) 2.isalnum #检测字符串是否由字母和数字组 ...

随机推荐

  1. sentiwordnet的简单使用

    # Example line: # POS     ID     PosS  NegS SynsetTerm#sentimentscore    Desc # a   00009618  0.5    ...

  2. Caffe + Ubuntu 14.04 64bit + CUDA 6.5 配置说明2

    1. 安装build-essentials 安装开发所需要的一些基本包 sudo apt-get install build-essential 2. 安装NVIDIA驱动 (3.4.0) 2.1 准 ...

  3. CefSharp访问需要认证网页或接口(在Request的Headers中添加认证Token)

    public class MyRequestHandler : DefaultRequestHandler { public static readonly string VersionNumberS ...

  4. 背水一战 Windows 10 (40) - 控件(导航类): AppBar, CommandBar

    [源码下载] 背水一战 Windows 10 (40) - 控件(导航类): AppBar, CommandBar 作者:webabcd 介绍背水一战 Windows 10 之 控件(导航类) App ...

  5. Android Parcelable using Kotlin

    Kotlin 有 extension 可以很方便的让类继承 Parcelable 接口. 项目中引入一个较新版本的 Kotlin 引入 Kotlin extensions classpath &quo ...

  6. ubuntu 环境 openstack 源码包制成 deb 包

    安装软件: sudo apt-get install dh-make checkinstall cd neutron sudo checkinstall -D -y -install=no -pkgv ...

  7. 初识node.js(通过npm下载项目依赖的包的过程)

    一.初识node.js 简单的说Node.js 就是运行在服务器端的JavaScript. Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台. Node.js是一个事 ...

  8. cmd命令关闭占用程序的端口

    遇到的问题: 在重新启动tomcat服务时,启动失败,显示的信息大概为:Error running 'cus_manager_system': Unable to open debugger port ...

  9. 谈一谈对MySQL InnoDB的认识及数据库事物处理的隔离级别

    介绍: InnoDB引擎是MySQL数据库的一个重要的存储引擎,和其他存储引擎相比,InnoDB引擎的优点是支持兼容ACID的事务(类似于PostgreSQL),以及参数完整性(有外键)等.现在Inn ...

  10. html头部标签大全

    http://www.css88.com/archives/8052#table-index