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

Show all messages Hide all messages

Здравствуйте!
Никак не могу понять где у меня проблема. На домашнем компьютере всё нормально работает, но здесь постоянно выдаёт WA.
Спасибо




#include <stdio.h>
#include <math.h>

int main(void) {

    long num;
    long double arr[100000];
    int position = 0;
    int asnwer;

    while ( ( asnwer = scanf("%lu", &num)) != EOF ) {
        if ( asnwer == 1 ) {
            arr[position] = num;
            position++;
        }
    }

    position--;

    while (position >= 0) {
        printf("%.4f\n", sqrt( arr[position] ));
        position--;
    }

    //getchar();

    return 0;
}
Re: Уже сдаюсь. Но моём компе нормально, здесь WA. Vedernikoff 'Goryinyich' Sergey (HSE: АОП) 3 Apr 2013 17:49
1. Your code is compiler-dependent: long == int on some compilers, so never use it. Use int or long long explicitly
2. Why do you think 100000 array is enough?
Thank you for your answer.
1) Ok, i made it.
2) Actually if i try to raise after 100.000 i get "Runtime error (stack overflow)". So maybe there is some another trick i didn't get.

Best regards
Use global array to avoid stack overflow