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

correct soulotion
Posted by acm_jtc2011 2 Nov 2011 03:11
#include<stdio.h>
#include "stdafx.h"
#include<conio.h>
#include<math.h>
#include<iostream>
double a[131072];
int main(){
int count=0;
int i=0;
while(std::cin>>a[i])
{    a[i]=sqrt(a[i]);
    count++;i++;}
for(int i=count-1;i>=0;i--)
    printf("\n%.4lf",a[i]);
    getch();
    return 0;

}
it's a correct code about this program
Re: correct soulotion
Posted by TedEBear 17 Feb 2012 21:05
Excuse me. Your code seems broken.
1) not working because of included headers.
2) Headers' names written in C style and C++ header
3) Using two counters. WHY, MAN, WHY.
4) Using realization-dependent headers(conio)

I present more correct one, C++.

#include <iostream>
//for cin
#include <cmath>
//for sqrt
#include <cstdio>
//for printf, replace with <iostream> if you need true cpp
// No unneeded headers.
using namespace std;
double nums[140000];
int main() {
    int x;
    for(x = 0; cin >> nums[x];x++) {;
        //Loop does everything for us. x isn't declared here because we need it outside.
    };
    //You can clearly see that only one counter is needed.
    x--;
    for(;x > -1; x--) {
        printf("%.4lf\n", sqrt(nums[x]));
        //Could use cout. How-to:
        //cout.precision(4);
        //cout << std::fixed;
        //Put them in the main(), not here.
    };
};

//Ted E. Bear saves the day. EOF.