c++简单题,跪求高手解答指错

来源:百度知道 编辑:UC知道 时间:2024/09/23 16:17:31
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 single integer T which is the number of test cases. T test cases follow.
Each test case contains a single line with several words. There will be at most 1000 characters in a line.

Output
For each test case, you should output the text which is processed.

Sample Input

3
olleh !dlrow
m'I morf .udh
I ekil .mca

Sample Output

hello world!
I'm from hdu.
I like acm.

Hint
Remember to use getchar() to read '\n' after the interger T, then you may use gets() to read a line and process it.

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
int i,t,c,x,j;

你现在的问题出在这里 cin>>c;
你需要在这句话后面加一句cin.ignore(1,'\n');
问题就是你出入c后回车了一下,那么输入缓冲区里面将保存这个回车符\n,第一次运行gets的时候,它得到了一个空串,就有内存问题了
当然了,改了这里之后,你后面程序的输出还是有点问题,但是问题是你的算法,而不是内存了