题目连接:

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. 解决rpm conflicts with file from package的两个方法

    1.卸载掉冲突的文件,安装新的文件.如果由于由于依赖关系导致要卸载很多软件,那可以优先考虑下一个方法. 2.安装的时候增加–replacefiles参数,例如 rpm -ivh xxx.rpm –re ...

  2. 火狐浏览器(Firefox)打开EBS form的设置方法

    http://yedward.net/?id=247 客户在使用EBS的时候,很多都是使用IE浏览器打开,但是EBS并不仅仅只是支持IE,对于谷歌浏览器(Chrome).火狐浏览器(Firefox)也 ...

  3. Memcached和Memcache安装(64位win2008)

    一.Memcached和Memcache的区别: 网上关于Memcached和Memcache的区别的理解众说纷纭,我个人的理解是: Memcached是一个内存缓存系统,而Memcache是php的 ...

  4. 微信WeixinJSBridge API使用实例

    http://www.jb51.net/article/66642.htm 这篇文章主要介绍了微信WeixinJSBridge API使用实例,本文直接给出HTML代码,代码中包含了很多实用功能,如图 ...

  5. 【转载】Configure the max limit for concurrent TCP connections

    转载地址:http://smallvoid.com/article/winnt-tcpip-max-limit.html To keep the TCP/IP stack from taking al ...

  6. node.js fs,http

    error: EventEmitter定义了一个特殊的时间error,它包含了‘错误’的语义,当error被发射时,EventEmitter规定如果没有 响应的监听器,Node.js会把它当做异常,退 ...

  7. 自定义WPF窗体形状

    介绍 你好WPF爱好者. 随着WPF等统一API语言的发明,丰富用户界面变得非常容易. 创建丰富的用户界面只是一个想法. 您需要拥有的是创造性思维和最新技术融合. WPF和Expression Ble ...

  8. [学习笔记]状压dp

    状压 \(dp\) 1.[SDOI2009]Bill的挑战 \(f[i][j]\) 表示匹配到字符串的第 \(i\) 位状态为 \(j\) 的方案数 那么方程就很明显了,每次枚举第 \(i\) 位的字 ...

  9. 网页关闭(解决window.close在火狐下不兼容问题)

    熟悉前端的都知道,火狐默认状态非window.open的页面window.close是无效的 网上有很多人说,在火狐的地址栏输入:about:config然后找到dom.allow_scripts_t ...

  10. day 72 crm(9) 客户关系系统,整体实现,以及自定制路由内容,客户关系梳理

    前情提要: crm(9)  ,利用stark 组件和,rbac组键的使用,   明确观点: 一:客户关系需求明确 1:客户关系系统,主要是,本业务逻辑主要是 销售就客户关系的业务逻辑, 二: 创建ap ...