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

Common Board

Maybe Problem in data input , dont know why am I getting wrong answers ...
Posted by Akash Gangil 9 Aug 2009 23:03
/*********Reverse Root***********/
/*
Program to input a stream of NO:s and beginning from the end of the stream , print their square root

--math.h is not linked by default in gcc , you have to link it by option -lm , in command . math.h is in libm , only libc functions are linked by default
--use strtod() to convert from string to double , stdlib.h


*/




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

/*function to reverse a string*/
void strrev(char string[256])
{
 char reverse[256];
 int i,j;
 i=strlen(string);

 for (j=i-1;j>=0;j--)
  {
    reverse[i-1-j]=string[j];
  }
  reverse[i]='\0';
  strcpy(string,reverse);
}


int main(void)
{

 int k=0,i=0,j,different=0,start=0;
 int c;
 char stream[256];
 char num[256];
 char copy[256];
 double number;
 while((c=getchar())!=EOF)
  {
   stream[i]=c;
   j=i;
   i++;
  }

 for (k=j;k>=0;k--)
  {
   if(isdigit(stream[k])!=0)
     {
       if(isdigit(stream[k-1])!=0)
        {
          num[start]=stream[k];
          start++;
        }
       else
        {
          num[start]=stream[k];
          num[start+1]='\0';
//          printf("%s\n",num);
          strrev(num);
//          printf("%s\n",num);
          strcpy(copy,num);
          number=strtod(copy,NULL);
          printf("%0.4f\n",sqrt(number));
          start=0;

        }
     }
  }

  return 0;

}

Can anybody tell me why does it gives wrong answer...?
Any help would be highly appreciated..