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 1030. Titanic

Why do I get WA? Help me, please!
Posted by Aleksei Zobnin 28 Sep 2002 16:06
I have read all comments below, but my program still gets WA...

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

int main () {
 int hh, dd, mm, danger, n;
 double x1, x2, x3, y1, y2, y3, a1, a2, a3, b1, b2, b3;
 char ns1, ns2, we1, we2;
 double x, y, z, a, b, c, res, Phi, Psi;
 char s1[3], s2[3], s3[3];
 const double R = 6875;
 const double Pi = 3.1415926;
 char s [100];
 int q = 1;
 while (q) {
  if (scanf ("Message #%d.\n", &n) == EOF) break;
  scanf ("Received at %2d:%2d:%2d.\n", &hh, &dd, &mm);
  scanf ("%[^\n]\n", s);
  scanf ("%2lf^%2lf'%2lf%c ", &x1, &x2, &x3, &c);
  scanf ("%cL\n", &ns1);
  scanf ("and %2lf^%2lf'%2lf%c ", &y1, &y2, &y3, &c);
  scanf ("%cL.\n", &we1);
  scanf ("%[^\n]\n", s);
  scanf ("%2lf^%2lf'%2lf%c ", &a1, &a2, &a3, &c);
  scanf ("%cL\n", &ns2);
  scanf ("and %2lf^%2lf'%2lf%c ", &b1, &b2, &b3, &c);
  scanf ("%cL.\n", &we2);
  scanf ("%[=]", s);
  if (scanf ("\n") == EOF) q = 0;
  Phi = Pi / 180 * (x1 + x2 / 60 + x3 / 3600);
  if (ns1 == 'S') Phi *= -1;
  Psi = Pi / 180 * (y1 + y2 / 60 + y3 / 3600);
  if (we1 == 'E') Psi *= -1;
  x = cos (Phi) * cos (Psi);
  y = cos (Phi) * sin (Psi);
  z = sin (Phi);
  Phi = Pi / 180 * (a1 + a2 / 60 + a3 / 3600);
  if (ns2 == 'S') Phi *= -1;
  Psi = Pi / 180 * (b1 + b2 / 60 + b3 / 3600);
  if (we2 == 'E') Psi *= -1;
  a = cos (Phi) * cos (Psi);
  b = cos (Phi) * sin (Psi);
  c = sin (Phi);
  res = R * acos (a*x + b*y + c*z) / 2;
  danger = (res < 99.995);
  if (res < 0.005) res = 0;
  printf ("The distance to the iceberg: %.2lf miles.\n", res);
  if (danger)
   printf ("DANGER!\n");
 };
 return 0;
}