ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1030. Titanic

What's wrong with my code. I always get WA
Posted by Li Yi 20 Aug 2001 11:31
#include <fstream.h>
#include <stdio.h>
#include <math.h>
#include <string.h>

const double D = 6875.;
const double R = 3437.5;
const double C_PI = 3.14159265358979323846;

int main ()
{
double phi1, phi2, teta1, teta2;
double degrees, minutes, seconds, sign;
double x1,x2,y1,y2,z1,z2;
char s[300];

cin.getline(s, 299);
cin.getline(s, 299);
cin.getline(s, 299);
cin.getline(s, 299);

degrees = atof(s);

char *p = strchr(s,'^');
minutes = atof(p + 1);

p = strchr(s, '\'');
seconds = atof(p + 1);

sign = 0.;
if (strstr(s, "SL") != NULL) sign = -1.;
if (strstr(s, "NL") != NULL) sign = 1.;

phi1 = sign * (degrees + minutes / 60. + seconds / 3600.);

cin >> s;
cin.getline(s, 299);

degrees = atof(s);

p = strchr(s, '^');
minutes = atof(p + 1);

p = strchr(s, '\'');
seconds = atof(p + 1);

sign = 0.;
if (strstr(s,"WL") != NULL) sign=-1.;
if (strstr(s,"EL") != NULL) sign=1.;

teta1 = sign * (degrees + minutes / 60. + seconds /
3600.);

// skip one line
cin.getline(s, 299);

cin.getline(s, 299);
p = strchr(s,'^');
degrees = atof(s);
minutes = atof(p+1);

p = strchr(s, '\'');
seconds = atof(p+1);

sign = 0.;
if (strstr(s, "SL") != NULL) sign=-1.;
if (strstr(s, "NL") != NULL) sign=1.;

phi2 = sign * (degrees + minutes / 60. + seconds / 3600.);

cin >> s;
cin.getline(s, 299);
degrees = atof(s);
p = strchr(s,'^');
minutes = atof(p + 1);

p = strchr(s, '\'');

seconds = atof(p + 1);

sign = 0.;
if (strstr(s, "WL") != NULL) sign = -1.;
if (strstr(s, "EL") != NULL) sign = 1.;
teta2 = sign * (degrees + minutes / 60. + seconds /
3600.);

// calculate the euclids coordinate
phi1  = phi1  * C_PI / 180.;
phi2  = phi2  * C_PI / 180.;
teta1 = teta1 * C_PI / 180.;
teta2 = teta2 * C_PI / 180.;

x1 = R * cos(phi1) * cos(teta1);
y1 = R * cos(phi1) * sin(teta1);
z1 = R * sin(phi1);

x2 = R * cos(phi2) * cos(teta2);
y2 = R * cos(phi2) * sin(teta2);
z2 = R * sin(phi2);

double dist = sqrt((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2)
+ (z1-z2) * (z1-z2));
double k = dist / D;
double way = D * asin(k);

printf("The distance to the iceberg: %4.2lf miles.\n",
way);
if ( way < 100.00 ) printf("DANGER\n");

return 0;
}
Of source, it must be "DANGER!\n", and it's still WA.
Posted by Li Yi 20 Aug 2001 11:43
Re: What's wrong with my code. I always get WA
Posted by ValkaVales 21 Aug 2001 14:21
Try

if (way < 99.95) ...
Re: What's wrong with my code. I always get WA
Posted by tester2 26 Jan 2002 19:50
> #include <fstream.h>
> #include <stdio.h>
> #include <math.h>
> #include <string.h>
>
> const double D = 6875.;
> const double R = 3437.5;
> const double C_PI = 3.14159265358979323846;
>
> int main ()
> {
>   double phi1, phi2, teta1, teta2;
>   double degrees, minutes, seconds, sign;
>   double x1,x2,y1,y2,z1,z2;
>   char s[300];
>
>   cin.getline(s, 299);
>   cin.getline(s, 299);
>   cin.getline(s, 299);
>   // read the ship coordinates
>   cin.getline(s, 299);
>
>   degrees = atof(s);
>
>   char *p = strchr(s,'^');
>   minutes = atof(p + 1);
>
>   p = strchr(s, '\'');
>   seconds = atof(p + 1);
>
>   sign = 0.;
>   if (strstr(s, "SL") != NULL) sign = -1.;
>   if (strstr(s, "NL") != NULL) sign = 1.;
>
>   phi1 = sign * (degrees + minutes / 60. + seconds / 3600.);
>
>   cin >> s;
>   cin.getline(s, 299);
>
>   degrees = atof(s);
>
>   p = strchr(s, '^');
>   minutes = atof(p + 1);
>
>   p = strchr(s, '\'');
>   seconds = atof(p + 1);
>
>   sign = 0.;
>   if (strstr(s,"WL") != NULL) sign=-1.;
>   if (strstr(s,"EL") != NULL) sign=1.;
>
>   teta1 = sign * (degrees + minutes / 60. + seconds /
> 3600.);
>
>   // skip one line
>   cin.getline(s, 299);
>   // read the iceberg coordinates
>
>   cin.getline(s, 299);
>   p = strchr(s,'^');
>   degrees = atof(s);
>   minutes = atof(p+1);
>
>   p = strchr(s, '\'');
>   seconds = atof(p+1);
>
>   sign = 0.;
>   if (strstr(s, "SL") != NULL) sign=-1.;
>   if (strstr(s, "NL") != NULL) sign=1.;
>
>   phi2 = sign * (degrees + minutes / 60. + seconds / 3600.);
>
>   cin >> s;
>   cin.getline(s, 299);
>   degrees = atof(s);
>   p = strchr(s,'^');
>   minutes = atof(p + 1);
>
>   p = strchr(s, '\'');
>
>   seconds = atof(p + 1);
>
>   sign = 0.;
>   if (strstr(s, "WL") != NULL) sign = -1.;
>   if (strstr(s, "EL") != NULL) sign = 1.;
>   teta2 = sign * (degrees + minutes / 60. + seconds /
> 3600.);
>
>   // calculate the euclids coordinate
>   phi1  = phi1  * C_PI / 180.;
>   phi2  = phi2  * C_PI / 180.;
>   teta1 = teta1 * C_PI / 180.;
>   teta2 = teta2 * C_PI / 180.;
>
>   x1 = R * cos(phi1) * cos(teta1);
>   y1 = R * cos(phi1) * sin(teta1);
>   z1 = R * sin(phi1);
>
>   x2 = R * cos(phi2) * cos(teta2);
>   y2 = R * cos(phi2) * sin(teta2);
>   z2 = R * sin(phi2);
>
>   double dist = sqrt((x1-x2) * (x1-x2) + (y1-y2) * (y1-y2)
> + (z1-z2) * (z1-z2));
>   double k = dist / D;
>   double way = D * asin(k);
>
>   printf("The distance to the iceberg: %4.2lf miles.\n",
> way);
>   if ( way < 100.00 ) printf("DANGER\n");
>
>   return 0;
> }
>
Re: What's wrong with my code. I always get WA
Posted by Seany 7 Aug 2003 14:06
change 'way<100.00' to '100.00-way>0.005'
then you will got accept;
Good luck!
Re: What's wrong with my code. I always get WA
Posted by The Punisher 25 Jan 2007 01:25
Thanks a lot!
Got AC!