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 #检测字符串是否由字母和数字组 ...
随机推荐
- jQuery插件初级练习4
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...
- 100度享乐电商网 CSS
/*reset begin*/body,div,dl,dt,p,h1,h2,h3,h4,h5,input,form,span,ul{ margin: 0; padding: 0;}a{ text-de ...
- javascript Object.create()究竟发生了什么
这是我在博客园的第一篇博客,早上看了一个大牛的博客,关于javascript继承的,对于大牛使用Object.create()实现继承的方式觉得点问题,就自己研究了一下,所以就有了这篇帖子. 本帖 ...
- cmd如何进入d盘
首先打开CMD 点开始 运行输入 CMD 在CMD窗口中输入 CD\(就是返回根目录) 回车 在输入 D: 即可在D盘操作状态
- 常见CEPH操作命令
1. rbd ls 查看ceph默认资源池rbd里面的镜像2. rbd info xxx.img 查看xxx.img的具体的具体信息3. rbd rm xxx.img 删除xxx.img4. rbd ...
- EBS 定义显示总帐快码设置
自定义一个功能如下,挂到菜单上就可以了功能 用户功能名 表单 参数GL_GLXDQMLK(自定义) 总帐代码列表 定义代码 VIEW_APPLICATION="SQLGL" HEL ...
- DevExpress GridControl 关于使用CardView的一点小结
最近项目里需要显示商品的一系列图片,打算用CardView来显示,由于第一次使用,遇到许多问题,发现网上这方面的资源很少,所以把自己的一点点实际经验小结一下,供自己和大家以后参考. 1.选择CardV ...
- DevExpress控件cxGrid实现多列模糊匹配输入的完美解决方案
本方案不需要修改控件源码,是完美解决cxgrid或TcxDBExtLookupComboBox支持多列模糊匹配快速输入的最佳方案!! 转自https://blog.csdn.net/qq5643020 ...
- OS基础:动态链接库(二)
1.vc6.0新建工程MFC AppWizard[dll]工程 命名LptMfcDll1 2.在lptMfcDll1.h添加函数名声明 添加的代码: //lptAddBegin void lptMfc ...
- 【BZOJ4827】 [Hnoi2017]礼物
BZOJ4827 [Hnoi2017]礼物 Solution 如果一串数的增加,不就等于另一串数减吗? 那么我们可以把答案写成另一个形式: \(ans=\sum_{i=1}^n(x_i-y_i+C)^ ...