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 Output(linklist L)
    {
    	linklist p;
    	p = L->next;
    	while (p != NULL)
    	{
    		printf("%d", p->number);
    		p = p->next;
    		if (p != NULL)
    		{
    			printf(" ");
    		}
    	}
    }
    int main()
    {
    	linklist list;
    	InputAndCreate(&list);
    	Output(list);
    	return 0;
    }
    

    C++ :

    #include <iostream>
    #include <deque>
    using namespace std;
    
    
    int main() {
    	deque<int> q;
    	
    	int x;
    	while (cin >> x) {
    		if (x == -1) break;
    		q.push_back(x);
    	}
    
    	for (int i = 0; i < q.size(); i ++) cout << q[i] << ' ';
    	
    	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:=1 to i-1 do
        write(a[i]^,' ');
        writeln(a[i+1]^)
      end.
    
    
    • 1

    Information

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