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

    C++ :

    #include <stdio.h>
    #include <stdlib.h>
    struct node
    {
    	int d;
    	node *next;
    };
    
    node *create();  // 建立链表
    void travel(node *head);   // 遍历链表,输出数据
    
    int main()
    {
    	node *head = create();
    	travel(head);
    
    	return 0;
    }
    node *create()
    {
    	node *head = (node *)malloc(sizeof(node));
    	head->next = NULL;
    	node *rear = head;
    	int a;
    	scanf("%d", &a);;
    	while(a > 0)
    	{
    		node *p = (node *)malloc(sizeof(node));
    		p->d = a;
    		p->next = NULL;
    		rear->next = p;
    		rear = p;
    		scanf("%d", &a);
    	}
    	return head;
    }
    void travel(node *head)
    {
    	int x;
    	scanf("%d", &x);
    	int flag = 0;
    	for(node *p = head->next; p != NULL; p = p->next)
    	{
    		if(p->d > x)
    		{
    			printf("%d ", p->d);
    			flag = 1;
    		}
    	}
    	if(flag == 0)
    		printf("no found");
    }
    

    Pascal :

    type pointer=^rec;
         rec=record
            data:int64;
            next:pointer;
            end;
    var p,q,head:pointer;
        i,j,k,a:longint;
    begin
      head:=nil;
      i:=0;
      read(a);
    while a>=0  do
      begin
      if head=nil then
        begin
        new(p);
        p^.data:=a;
        p^.next:=nil;
        q:=p;
        head:=p;
        end
      else
      begin
        new(p);
        p^.data:=a;
        p^.next:=nil;
        q^.next:=p;
        q:=p;
        end;
        read(a);
      end;
        readln(k);
        p:=head;
        while p<>nil do
          begin
           if (p^.data>k) then
           begin
             write(p^.data,' ');
             inc(i);
           end;
            p:=p^.next;
          end;
        if i=0 then
         writeln('no found');
    end.
    
    • 1

    Information

    ID
    510
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    7
    Accepted
    0
    Uploaded By