Word Reversal (简单字符串处理)
题目描述:
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.
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
//题意描述:输入一个字符串,不改变单词的顺序,将每个单词反转输出
//解题思路: 用gets读入,去头去尾后,判断出一个单词,将其复制到另一个字符串中逆序输出,直至字符串尾即可
#include<stdio.h>
#include<ctype.h>
#include<string.h> void pri(char p[])
{
int i,l=strlen(p);
for(i=;i<l;i++)
printf("#%c",p[i]);
printf("\n");
} int main()
{
int T,r,i,j,k;
char s[],*p=NULL,s2[];
scanf("%d",&T);
while(T--)
{ scanf("%d",&r);
getchar();
while(r--)
{
gets(s);
int l=strlen(s);
s[l]='\0';
//pri(s); p=s;
while(!isalpha(*p))
{
p++;
}
//pri(p); l=strlen(p);
for(i=l-;i>=;i--)
if(isalpha(p[i]))
break;
p[i+]=' ';
p[i+]='\0';
//pri(p); l=strlen(p);
for(i=;i<l;)
{
j=;
while(isalpha(p[i]))
{
s2[j++]=p[i++];
}
s2[j]='\0'; for(k=j-;k>=;k--)
printf("%c",s2[k]); if(i==l-)
printf("\n");
else
printf(" ");
i++;
}
}
if(T != )
printf("\n");
}
return ;
}
//易错分析
//gets之前要吃掉换行
最新文章
- WCF学习之旅—WCF中传统的异常处理(十六)
- JS产生随机数的几个用法!
- 【转】MongoDB安全配置
- NUnit-Console 命令行选项详解
- A woman without arms
- (转)推荐一个在Linux/Unix上架设ASP.NET的 WEB服务器--Jexus
- java 执行sql脚本的3种方式 (ant,ibatis,ScriptRunner)
- CGRectInset CGRectoffset UIEdgeInsetsInsetRect 这三个函数的使用情况
- React使用笔记1-React的JSX和Style
- vs2013 ADO联系SQL server2012数据库
- 如何取消Microsoft账户登录电脑
- ASP.NET页面之间的几种传值方法
- coTurn 运行在Windows平台的方法及服务与客户端运行交互流程和原理
- 『TensorFlow』卷积层、池化层详解
- [UE4]Wrap Box流布局
- 启动设置mongodb
- 微软BI 之SSIS 系列 - 在 SSIS 中使用 Web Service 以及 XML 解析
- shlve 模块
- Java 集成开发环境的介绍及下载
- codeforces 559b//Equivalent Strings// Codeforces Round #313(Div. 1)
热门文章
- [php] php - json_encode 函数
- google breakpad for linux(2)
- 201621123018《java程序设计》第13周作业总结
- python中硬要写抽象类和抽象方法
- PANIC: Missing emulator engine program for &#39;x86&#39; CPU.
- win7 docker 挂载共享目录
- Linux上安装java JDK
- 移动一根火柴使等式成立js版本(递归)
- flask_ Mongodb 的语法-排序
- [POC]K8 DLLhijack Test