题解报告:hdu 1062 Text Reverse

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062

解题思路:问题求解的是单词的反转。。。

AC代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char a[1005];
 4 int main()
 5 {
 6     int T,len,x,y;
 7     while(cin>>T){
 8         getchar();//吃掉回车符
 9         while(T--){
10             gets(a);
11             len=strlen(a);
12             for(int i=0;i<len;++i){
13                 x=i;//标记当前单词的起始坐标
14                 while(a[i]!=‘ ‘ && a[i]!=‘\0‘)++i;//循环直到遇到空字符
15                 y=i-1;//标记单词尾
16                 for(int j=y;j>=x;--j)
17                     printf("%c",a[j]);//反序输出
18                 if(a[i]==‘ ‘)cout<<‘ ‘;//如果此时a[i]是空字符的haul顺便输出
19             }
20             cout<<endl;//换行
21         }
22     }
23     return 0;
24 }

原文地址:https://www.cnblogs.com/acgoto/p/8635407.html

时间: 2024-11-10 01:29:19

题解报告:hdu 1062 Text Reverse的相关文章

hdu 1062 Text Reverse 字符串反转

Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 18240    Accepted Submission(s): 6900 Problem Description Ignatius likes to write words in reverse way. Given a single line of text

HDU 1062.Text Reverse【栈或数组或字符串流】【字符处理】【8月30】

Text Reverse Problem Description Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. Input The input contains several test cases. The first lin

HDU 1062 Text Reverse(水题,字符串处理)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1062 解题报告:注意一行的末尾可能是空格,还有记得getchar()吃回车符. 1 #include<cstdio> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 #include<cmath> 6 #include<deque> 7 #include&

HDOJ/HDU 1062 Text Reverse(字符串翻转~)

Problem Description Ignatius likes to write words in reverse way. Given a single line of text which is written by Ignatius, you should reverse all the words and then output them. Input The input contains several test cases. The first line of the inpu

[hdu 1062] Text Reverse | STL-stack

原题 题目大意: t组数据,每组为一行,遇到空格时讲前面的单词反转输出. 题解: 显然的栈题,遇到空格时将当前栈输出清空即可 #include<cstdio> #include<stack> #include<cstring> using namespace std; int t,l; char s[1010]; stack <char> stk; int main() { scanf("%d",&t); getchar(); w

HDU 1062 Text Reverse

字符串反转:每个单词反转,然后输出. PE做法:所有单词反转并写入另一个数组中,附代码 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int N=1005; 6 int main() { 7 char ol[N],no[N]; 8 int n; 9 // freopen("C:\\CODE\\in.txt",

【HDOJ】1062 Text Reverse

#include<iostream>#include<string>using namespace std;void main(){ int T; while (cin>>T) { getchar(); for (int i = 0; i < T; i++) { string str; getline(cin, str); int end = 0,top = 0; while (str[end] != '\0') { if (str[end]==' ') { fo

2019.11.11 题解报告

目录 2019.11.11 题解报告 答题情况: 各题目分析: 题目解析: 代码实现: 2019.11.11 题解报告 \[N^2\text{狂草1e5它不香嘛?}\] \[\text{By:Unluckierblock}\] 答题情况: 总成绩 : 169, 排名: 11 / 32 T1 : 0 T2 : 99 T3 : 70 各题目分析: 题目 1 : 预估成绩 : 60 实际成绩 : 0 考试用时 : 8 : 00 ~ 8 : 50 , 9 : 50 ~ 10 : 10 没有什么感觉 ,

题解报告:hdu 1162 Eddy&#39;s picture

Problem Description Eddy begins to like painting pictures recently ,he is sure of himself to become a painter.Every day Eddy draws pictures in his small room, and he usually puts out his newest pictures to let his friends appreciate. but the result i