zoj 1151 Word Reversal(字符串操作模拟)
题目连接:
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(字符串操作模拟)的更多相关文章
- ZOJ 1151 Word Reversal反转单词 (string字符串处理)
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151 For each list of words, output a l ...
- ZOJ 1151 Word Reversal
原题链接 题目大意:给一句话,把每个单词倒序,然后输出. 解法:我是用了一个堆栈,以空格来拆分单词,把每个字母压入堆栈,然后依次输出. 参考代码: /* * 字符串反向,140ms,188kb * 单 ...
- zoj1151 zoj1295 Word Reversal 字符串的简单处理
Word Reversal Time Limit: 2 Seconds Memory Limit:65536 KB For each list of words, output a line ...
- Luogu 1098 - 字符串的展开 - [字符串操作][模拟]
题目链接:https://www.luogu.org/problemnew/show/P1098 题目描述在初赛普及组的“阅读程序写结果”的问题中,我们曾给出一个字符串展开的例子:如果在输入的字符串中 ...
- linux makefile字符串操作函数 替换subst、模式替换patsubst、去首尾空格strip、查找字符串findstring、过滤filter、反过滤filter-out、排序函数sort、取单词word、取单词串wordlist、个数统计words
1.1 字符操作函数使用 在Makefile中可以使用函数来处理变量,从而让我们的命令或是规则更为的灵活和具有智能.make所支持的函数也不算很多,不过已经足够我们的操作了.函数调用后,函 ...
- [No000078]Python3 字符串操作
#!/usr/bin/env python3 # -*- coding: utf-8 -*- '''Python 字符串操作 string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分 ...
- Python 字符串操作及string模块使用
python的字符串操作通过2部分的方法函数基本上就可以解决所有的字符串操作需求: python的字符串属性函数 python的string模块 1.字符串属性方法操作: 1.>字符串格式输出对 ...
- c# 字符串操作
一.字符串操作 //字符串转数组 string mystring="this is a string" char[] mychars=mystring.ToCharArray(); ...
- day8(字符串操作)
一.字符串操作 1.index #返回字符串的索引值 s = "Hello word" print(s.index('o')) 2.isalnum #检测字符串是否由字母和数字组 ...
随机推荐
- [Chrome_Error] (failed) net::ERR_INCOMPLETE_CHUNKED_ENCODING 与 nginx 502 bad gateway
Chrome 浏览器出现这个错误,还出现 nginx 502 bad gateway . 查看 nginx 的 error.log : 2015/12/18 14:34:44 [error] 1448 ...
- 火狐浏览器(Firefox)打开EBS form的设置方法
http://yedward.net/?id=247 客户在使用EBS的时候,很多都是使用IE浏览器打开,但是EBS并不仅仅只是支持IE,对于谷歌浏览器(Chrome).火狐浏览器(Firefox)也 ...
- java解决共享资源竞争
由于多线程的实现,在运行一个程序的时候可能会有很多的线程在同时运行,但是线程的调度并不是可见的,所以不会知道一个线程什么时候在运行,比如说 你坐在桌子前手拿着叉子,正要去叉盘中的最后一片食物,当你的叉 ...
- WinForm POST上传与后台接收
前端 using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using ...
- ZedGraph设置辅助线
ZedGraph设置辅助线 1.一般来说ZedGraph设置参考线可以用 ZedGraph对象.YAxis.MajorGrid.IsVisible = True '水平参考线 ZedGraph对象.X ...
- DEV通过FindFilterText自动检索gridview内容
private void TreeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) { if (names!=nul ...
- openvSwitch 基本命令
建立ovs接口连接两个namespace组成二层网络 环境搭建拓扑 br0 +--------------------------------------+ +--+ +--+ +---+ | tap ...
- 微服务统一登陆认证怎么做?JWT ?
无状态登录原理 1.1.什么是有状态? 有状态服务,即服务端需要记录每次会话的客户端信息,从而识别客户端身份,根据用户身份进行请求的处理,典型的设计如tomcat中的session. 例如登录:用户登 ...
- 模拟ssh、黏包、hashlib模块
一.模拟ssh 1.subprocess模块 ipconfig -all dir subprocess模块是python从2.4版本开始引入的模块.主要用来取代 一些旧的模块方法,如os.system ...
- java.lang.System.setProperty()方法实例
java.lang.System.setProperty() 方法设置指定键指定的系统属性. 声明 以下是java.lang.System.setProperty()方法的声明 public stat ...