Programming Ability Test学习 1009. 说反话 (20) 1009. 说反话 (20)

时间限制
400 ms
内存限制
65536 kB
代码长度限制
8000 B
判题程序
Standard
作者
CHEN, Yue

给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。

输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。

输出格式:每个测试用例的输出占一行,输出倒序后的句子。

输入样例:
Hello World Here I Come
输出样例:
Come I Here World Hello

提交代码

注:用链表头插法实现

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm> 
#define MAXSIZE 100005
using namespace std;

//结点结构 
typedef struct Node
{
    char s[100];
    struct Node *Next;
}node; 

//链表结构,每条链表有一个头结点和一个尾结点 
typedef struct Link
{
    node *head;
}link;

//创建一个新链表 
link *CreateNewLink(link *tLink)
{
    tLink->head=(node*)malloc(sizeof(node));
    tLink->head->Next=NULL;
    return tLink; 
} 

//输入s,生成链表,头插法 
void putNewLink(link *tLink,char *s)
{
    node *newPoint=(node*)malloc(sizeof(node));
    strcpy(newPoint->s,s);
    newPoint->Next=tLink->head->Next;
    tLink->head->Next=newPoint;
} 

//直接头结点后一个结点开始遍历即可,顺序已反 
void ReadLink(link *tLink)
{
    node* pthis=tLink->head->Next;
    while(pthis!=NULL)
    {
        cout<<pthis->s;
        if(pthis->Next==NULL)cout<<endl;
        else cout<<" ";
        pthis=pthis->Next;
    }
} 

int main()
{
    link *newLink=(link*)malloc(sizeof(link));
    newLink=CreateNewLink(newLink);
    char s[MAXSIZE];
    char ss[100];
    memset(s,0,sizeof(s));
    memset(ss,0,sizeof(ss));
    gets(s);
    int i=0,j=0;
    while(s[i]!='