ACM step 1.2.2 Text Reverse

gnatius 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.

一个简单的回文输出。。然后请原谅我的冗长的代码,之前很久没写程序了。。

//

//  main.cpp

//  hdu1.2.2

//

//  Created by wuxi on 14-10-22.

//  Copyright (c) 2014年 wuxi. All rights reserved.

//

#include <iostream>

#include <cstring>

#include <cstdio>

int T,num=0;

char a;

char b[10000];

void add(char c)

{

for (int i=0;i<=10000;i++)

if (b[i]==‘\0‘)

{

b[i]=c;

num++;

break;

}

}

void print()

{

for (int i=num-1;i>=0;i--)

printf("%c",b[i]);

num=0;

memset(b,0,sizeof(b));

}

int main() {

memset(b,0,sizeof(b));

scanf("%d",&T);

getchar();

while (T--)

{

while(scanf("%c",&a)!=EOF)

{

if (a==‘ ‘)

{

print();

printf(" ");

}

else if (a==‘\n‘)

{

print();

putchar(‘\n‘);

break;

}else add(a);

}

}

//print();

return 0;

}

时间: 2024-10-13 23:14:27

ACM step 1.2.2 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

Text Reverse(杭电oj1062)

Text Reverse Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 17702    Accepted Submission(s): 6717 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

Text Reverse

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 input is a s

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

hdu1062 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 c

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&

杭电oj1062 Text Reverse

Tips:使用一个临时数组c[1000] ,将输入的数据一边复制一边处理,碰到空格时就将前面的字符反向输出即可 1 #include<stdio.h> 2 #include<string.h> 3 ///使用一个临时数组c[1000] ,将输入的数据一边复制一边处理 4 void reverse(char s[]){ 5 char c[1000]; 6 int i,j,k; 7 for(i=0,j=0;i<strlen(s);i++){ 8 c[j++]=s[i]; 9 if

题解报告: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