zoukankan      html  css  js  c++  java
  • 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]!=''&&s[i]!=' ')
        {
            ss[j++]=s[i];
            //遇到空格 
            if(s[i+1]==' '&&s[i+2]!=' '){
            putNewLink(newLink,ss);
            memset(ss,0,sizeof(ss));
            j=0;
            i+=2;
            }
            //遇到串尾 
            else if(s[i+1]=='')
            {
                putNewLink(newLink,ss);
                break;
            }
            else i++;
        }
          ReadLink(newLink);
        //cout<<newLink->head->Next->s<<endl;
        //puts(s);
        
        return 0;
    } 
    View Code
  • 相关阅读:
    输入设备驱动
    Windows下Eclipse+PyDev安装Python开发环境
    Wireshark does not show SSL/TLS
    error trying to exec 'cc1plus': execvp: 没有那个文件或目录
    json 的key值不能是变量
    获取url参数(jq 扩展包)
    jsonp 完成跨域请求注意事项
    怎样删除数据库表中所有的数据
    sqlserver中数据的四种插入方式
    DataGridView
  • 原文地址:https://www.cnblogs.com/a842297171/p/4775996.html
Copyright © 2011-2022 走看看