poj 2354 Titanic(球面两点距离)

Titanic
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 1715   Accepted: 427

Description

It is a historical fact that during the legendary voyage of "Titanic" the wireless telegraph machine had delivered 6 warnings about the danger of icebergs. Each of the telegraph messages described the point where an iceberg had been noticed. The first five warnings were transferred to the captain of the ship. The sixth one came late at night and a telegraph operator did not notice that the coordinates mentioned were very close to the current ship's position. 

Write a program that will warn the operator about the danger of icebergs!

Input

The input messages are of the following format: 
Message #<n>.

Received at <HH>:<MM>:<SS>. 

Current ship's coordinates are 

<X1>^<X2>'<X3>" <NL/SL> 

and <Y1>^<Y2>'<Y3>" <EL/WL>.

An iceberg was noticed at 

<A1>^<A2>'<A3>" <NL/SL> 

and <B1>^<B2>'<B3>" <EL/WL>.

===

Here <n> is a positive integer, <HH>:<MM>:<SS> is the time of the message reception, <X1>^<X2>'<X3>" <NL/SL> and <Y1>^<Y2>'<Y3>" <EL/WL> means "X1 degrees X2 minutes X3 seconds of North (South) latitude and Y1 degrees Y2 minutes Y3 seconds of East (West) longitude."

Output

Your program should print to the output file message in the following format: 
The distance to the iceberg: <s> miles.

Where <s> should be the distance between the ship and the iceberg, (that is the length of the shortest path on the sphere between the ship and the iceberg). This distance should be printed up to (and correct to) two decimal digits. If this distance is less than (but not equal to!) 100 miles the program should print one more line with the text: 
DANGER!

Sample Input

Message #513.
Received at 22:30:11. 
Current ship's coordinates are 
41^46'00" NL 
and 50^14'00" WL.
An iceberg was noticed at
41^14'11" NL 
and 51^09'00" WL.
===

Sample Output

The distance to the iceberg: 52.04 miles.
DANGER!

Hint

For simplicity of calculations assume that the Earth is an ideal sphere with the diameter of 6875 miles completely covered with water. Also you can be sure that lines in the input file break exactly as it is shown in the input samples. The ranges of the ship and the iceberg coordinates are the same as the usual range for geographical coordinates, i.e. from 0 to 90 degrees inclusively for NL/SL and from 0 to 180 degrees inclusively for EL/WL.

Source

Ural Collegiate Programming Contest 1999

题目:http://poj.org/problem?id=2354

题意:有关泰坦尼克号的,给你冰山的经纬度,和船的经纬度,要求出他们的距离

分析:这题没什么难度,重点是细节上的问题,读入繁琐,不过对我来说没什么,然后需要注意的就是比较大小那个,需要进位后再比较就行,总体上是个水题

PS:忘记去掉多余的输出啊,wa了= =

代码:

#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
double a1,b1,a2,b2,d,r=6875/2.0;
char s[99];
double Dis3D(double a1,double b1,double a2,double b2)
{
    return r*acos(sin(a1)*sin(a2)+cos(a1)*cos(a2)*cos(b1-b2));
}
int Get()
{
    int a=0;
    char c;
    while((c=getchar())<'0'||c>'9');
    for(;c>='0'&&c<='9';c=getchar())a=a*10+c-'0';
    return a;
}
void GetA(double &a)
{
    a=Get()+Get()/60.0+Get()/3600.0;
    scanf("%s",s);
    if(s[0]=='S'||s[0]=='W')a=-a;
    a=a*acos(-1.0)/180;
}
int main()
{
    while(gets(s),s[0]!='=')
    {
        GetA(a1),GetA(a1),GetA(b1),GetA(a2),GetA(b2);
        d=Dis3D(a1,b1,a2,b2);
        printf("The distance to the iceberg: %.2lf miles.\n",d);
        if(floor(d+0.005)<100)puts("DANGER!");
        gets(s);
    }
    return 0;
}


你可能感兴趣的:(File,Integer,input,output,distance,Warnings)