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<cstdlib>
 8 using namespace std;
 9
10 const int maxn = 1000 + 5;
11
12 char temp[maxn],str[maxn];
13
14 int main()
15 {
16     int T;
17     scanf("%d",&T);
18     getchar();
19     while(T--)
20     {
21         gets(str);
22         int len = strlen(str),f = 0,flag = 1;
23         for(int i = 0;i < len;++i)
24         {
25             if(str[i] != ‘ ‘)
26             temp[f++] = str[i];
27             if(str[i] == ‘ ‘ || i == len - 1)
28             {
29                 temp[f] = NULL;
30                 reverse(temp,temp+f);
31                 printf("%s",temp);
32                 if(i != len - 1 || str[i] == ‘ ‘) printf(" ");
33                 f = 0;
34             }
35         }
36         puts("");
37     }
38     return 0;
39 }

时间: 2024-12-08 21:02:30

HDU 1062 Text Reverse(水题,字符串处理)的相关文章

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 字符串反转

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

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

题目链接: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

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",

[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

简单的dp hdu 数塔(水题)

数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 21314    Accepted Submission(s): 12808 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少

hdu 2053 Switch Game 水题一枚,鉴定完毕

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10200    Accepted Submission(s): 6175 Problem Description There are many lamps in a line. All of them are off at first. A series of op

HDU 2090 算菜价 --- 水题

/* HDU 2090 算菜价 --- 水题 */ #include <cstdio> int main() { char s[105]; double a, b, sum = 0; while (scanf("%s", s)==1){ scanf("%lf%lf", &a, &b); a *= b; sum += a; } printf("%.1f\n", sum); return 0; }