1 条题解

  • 0
    @ 2025-11-30 16:27:50

    C++ :

    #include<malloc.h>
    #include<iostream>
    using namespace std;
    
    typedef struct Node
    {
    	char data;
    	struct Node *next;
    }Node, *Linklist;
    
    void InitList(Linklist *L)
    {
    	*L =(Linklist)malloc(sizeof(Node));
    	(*L)->next = NULL;
    }
    	
    void Create_rear(Linklist L,int n)
    {
    	Node *s,*r;
    	char c;
    	bool flag =true;
    	r=L;
    	for(int i=0;i<n;i++)
    	{
    		cin>>c;
    		if(i!=n)
    		{
    			s=(Node*)malloc(sizeof(Node));
    			s->data = c;
    			r->next = s;
    			r = s;
    		}
    		else
    		{
    			flag=0;
    			r->next=NULL;
    		}
    	}
    	return;
    }
    	
    
    
    void Out_Put(Linklist L,int n)
    {
    	Node *p;
    	p=L;
    	bool flag=true;
    	for(int i=0;i<n;i++)
    	{
    		p=p->next;
    		if(flag)
    		{
    			cout<<p->data;
    			flag=false;
    		}
    		else
    			flag=true;
    	}
    
    }
    
    int main()
    {
    	Linklist L;
    	int n;
    	cin>>n;
    	InitList(&L);
    	Create_rear(L,n);
    	Out_Put(L,n);
    	return 0;
    }
    
    • 1

    信息

    ID
    1398
    时间
    10000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者