ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1001. Reverse Root

C: Whats wrong with task?
Posted by Nick 11 Feb 2018 02:01
I've created file with tests, it seems all checks passes locally, but not in Judge
here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct list_node{
    long int number;
    struct list_node * previous;
} list_node_t;

list_node_t * create_root(long int number);
list_node_t * create_list(long int number, list_node_t * previous);

int main() {
    long int a;
    list_node_t * current = NULL;
    while (scanf("%ld", &a) != EOF) {
        if (current == NULL) {
            current = create_root(a);
        } else {
            current = create_list(a, current);
        }
    }

    while (current != NULL) {
        printf("%.4Lf\n\r", sqrtl(current->number));
        current = current->previous;
    }

    return 0;
}

list_node_t * create_root(long int number)
{
    list_node_t *lt = malloc(sizeof(list_node_t));

    lt->number = number;
    lt->previous = NULL;

    return lt;
}

list_node_t * create_list(long int number, list_node_t * previous)
{
    list_node_t *lt = create_root(number);

    lt->previous = previous;

    return lt;
}
Re: C: Whats wrong with task?
Posted by Diego Iturra 22 Mar 2019 07:43
the problem is just calculate the square root in reverse order, it is unnecesary create a linked list or use pointer