1 solutions

  • 0
    @ 2024-12-10 22:03:04

    C :

    #include<stdio.h>
    #include<stdlib.h>
    typedef struct tagNODE
    {
    	int number;
    	struct tagNODE* next;
    }node, * linklist;
    void InputAndCreate(linklist* L)
    {
    	linklist p, s;
    	int n;
    	p = *L = (linklist)malloc(sizeof(node));
    	while (scanf("%d", &n), n >= 0)
    	{
    		s = (linklist)malloc(sizeof(node));
    		s->number = n;
    		p->next = s, p = s;
    	}
    	p->next = NULL;
    }
    void rOutput(linklist L)
    {
    	L = L->next;
    	if (L->next != NULL)
    	{
    		rOutput(L);
    		printf("%d ", L->number);
    	}
    	else
    	{
    		printf("%d ", L->number);
    		return;
    	}
    }
    int main()
    {
    	linklist list;
    	InputAndCreate(&list);
    	rOutput(list);
    	return 0;
    }
    

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    
    struct node{
    	int data;
    	node *next;
    };
    
    void Travel(node *head){
    	while(head!=NULL){
    		cout<<head->data<<" ";
    		head = head->next;
    	} 
    }
    int main()
    {
    	node *p,*h,*head;
    	p=NULL;
    	int x;
    	while(cin>>x&&x!=-1){
    		h = new node;
    		h->data = x; 
    		h->next = p;
    		p = h;
    	} 
    	head = p;
    	Travel(head);
    	return 0;
    }
    
    

    Pascal :

    var a:array[1..500]of ^int64;
        i,j,k:longint;
    begin
      i:=1;
      new(a[1]);
      read(a[i]^);
      while a[i]^ >=0 do
        begin
          inc(i);
          new(a[i]);
          read(a[i]^);
        end;
      i:=i-1;
      for i:=i downto 2 do
        write(a[i]^,' ');
        writeln(a[1]^)
      end.
    
    • 1

    Information

    ID
    523
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By