HDU 1062

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;

int main(){
  char a[1010];
  int n;
  cin >> n;
  cin.get(); //空格还是得吸的
  while(n --){
    gets(a);
    int length = strlen(a); //获取字符串长度
    int k = -1;
    for(int i = 0; i <= length; i ++){
      if(a[i] == ‘ ‘ || i == length){
        for(int j = i - 1; j != k && j >= 0; j --){
          putchar(a[j]);
        }
        k = i;
        if(i != length)
          putchar(‘ ‘);
         }
      }
      cout << endl;
    }
   return 0;
}

原文地址:https://www.cnblogs.com/Elvis827/p/8626438.html

时间: 2024-11-02 18:13:28

HDU 1062的相关文章

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&

题解报告: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 字符串反转

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【栈或数组或字符串流】【字符处理】【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

stack的使用-Hdu 1062

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

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(DFS)

昂贵的聘礼 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 44870   Accepted: 13259 Description 年 轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用10000个金币作为聘礼才答应把女儿嫁给他.探险家拿 不出这么多金币,便请求酋长降低要求.酋长说:"嗯,如果你能够替我弄到大祭司的皮袄,我可以只要8000金币.如果你能够弄来他的水晶球,那么只要 5

J - Text Reverse HDU - 1062

格式错误2遍:没考虑到连续两个空格的情况,遇到空格最后要输出这个空格,因为题目只需要转换单词. 另外,开cin,cout加速要注意读入不能用scanf,printf,puts,getchar这些.getline,streamstream 可以结合使用 代码: using namespace std; #define maxn 19999 #define rep(i,a,b) for(int i=(a);i<(b);i++) #define ll long long string s; strin