当前位置:网站首页>Titanic(POJ2361)
Titanic(POJ2361)
2022-06-30 03:55:00 【Cod_ ing】
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!
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
^’" <NL/SL>
and ^’" <EL/WL>.
===
Here is a positive integer, :: 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!
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
using namespace std;
double pi=acos(-1.0); // acos() Function does not accept int type , Otherwise, a compilation error will occur
double R=3437.5; // Earth radius ( miles )
inline void change(double &x,double &y){
x=x*pi/180;
y=y*pi/180;
}
//A(wa,jb),B(wx,jy),w Represent dimension ; j It means longitude . North latitude 、 The east longitude is taken as the right
void distance(double a,double b,double x,double y){
double d;
// To calculate the distance between two points on the earth , Please deduce
d=R* acos(cos(a)*cos(x)*cos(b-y)+sin(a)*sin(x));
printf("The distance to the iceberg: %.2lf miles.\n",d);
if(floor(d+0.005)<100)
cout<<"DANGER!\n";
}
int main(){
string s;
double a1,a2,a3,b1,b2,b3,shipw,shipj,icebergw,icebergj;
char a,b;
int i;
for(i=0;i<3;i++)
getline(cin,s);
scanf("%lf^%lf'%lf\" %cL ",&a1,&a2,&a3,&a);
scanf("and %lf^%lf'%lf\" %cL.",&b1,&b2,&b3,&b);
shipw=a1+ a2/60+ a3/3600;
shipj=b1+ b2/60+ b3/3600;
if(a=='S') shipw*=-1;
if(b=='W') shipj*=-1;
change(shipw,shipj);
getchar(); // When getline function Used before scanf function need getchar() The read was not scanf Read about \n
getline(cin,s);
scanf("%lf^%lf'%lf\" %cL ",&a1,&a2,&a3,&a);
scanf("and %lf^%lf'%lf\" %cL.",&b1,&b2,&b3,&b);
icebergw=a1+ a2/60 +a3/3600;
icebergj=b1+ b2/60 +b3/3600;
if(a=='S') icebergw*=-1;
if(b=='W') icebergj*=-1;
change(icebergw,icebergj);
getchar();
getline(cin,s);
distance(shipw,shipj,icebergw,icebergj);
}
边栏推荐
- 【云原生】AI云开发平台——AI Model Foundry介绍(开发者可免费体验AI训练模型)
- Analysis of similarities and differences of various merged features (Union, merge, append, resolve) in ArcGIS
- Version correspondence table of tensorflow, CUDA and bazel
- 使用IDEAL连接数据库,运行出来了 结果显示一些警告,这部分怎么处理
- Wang Shuang - assembly language learning summary
- laravel9本地安装
- Postman learning sharing
- I have published a book, "changing life against the sky - the way for programmers to become gods", which is open source. I have been working for ten years. There are 100 life suggestions from technica
- GIS related data
- Hebb and delta learning rules
猜你喜欢

绿色新动力,算力“零”负担——JASMINER X4系列火爆热销中

Grasp grpc communication framework in simple terms

Laravel9 local installation

【筆記】AB測試和方差分析

RPC correction

ThingsBoard教程(二三):在规则链中计算二个设备的温度差

【笔记】2022.5.27 通过pycharm操作MySQL

laravel9本地安裝

The school training needs to make a registration page. It needs to open the database and save the contents entered on the registration page into the database

华为云原生——数据开发与DataFactory
随机推荐
Pytorch Profiler+ Tensorboard + VS Code
dotnet-exec 0.5.0 released
[frequently asked questions] modularization of browser environment and node environment
【论文阅读|深读】DANE:Deep Attributed Network Embedding
Hash design and memory saving data structure design in redis
Selenium environment installation, 8 elements positioning --01
. Net 7 JWT configuration is too convenient!
Mysql性能优化(5):主从同步原理与实现
Magical Union
[0x0] 校长留的开放问题作业
EasyCVR部署服务器集群时,出现一台在线一台不在线是什么原因?
Jour 9 Gestion des scripts et des ressources
解决navicat连接数据库遇到的问题
华为云原生——数据开发与DataFactory
Ubuntu20.04 PostgreSQL 14 installation configuration record
【模糊神经网络预测】基于模糊神经网络实现水质预测含Matlab源码
(03).NET MAUI实战 基础控件
[note] on May 28, 2022, data is obtained from the web page and written into the database
NER中BiLSTM-CRF解读score_sentence
Hebb and delta learning rules