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

1001. Reverse Root
Posted by Suraj Sharma 20 Jun 2019 11:03
The following code is failing the test case 3, I have used linked-list to store the data in as a stack. Below is the code for reference, can you tell me where I am going wrong. Thank you.

#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<math.h>
#include<assert.h>

typedef unsigned long long _ull;
typedef unsigned int _uint;

typedef struct _link_list {
    _ull _number;
    struct _link_list*_next;
} _list;

void _makenode(_list**,_ull);
void _insertnode(_list**,_list*);

int main(int argc,const char*argv[]) {
    _ull _val;
    _list *_head,*_temp;
    _head = _temp = NULL;
    while(true) {
        fscanf(stdin,"%lld",&_val);
        assert(_val>=0);
        if(feof(stdin)) break;
        _makenode(&_head,_val);
    }
    while(_head) {
        _temp = _head;
        fprintf(stdout,"%0.4lf\n",sqrt(_head->_number));
        _head = (_head->_next);
        free(_temp);
    }
    return 0;
}

void _makenode(_list**_ptr,_ull _data) {
    _list*_node = malloc(sizeof(_list));
    (_node->_number) = _data;
    (_node->_next) = NULL;
    _insertnode(_ptr,_node);
}

void _insertnode(_list**_ptr,_list*_node) {
    if(!(*_ptr)) (*_ptr) = _node;
    else {
        (_node->_next) = (*_ptr);
        (*_ptr) = _node;
    }
}