当前位置:网站首页>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);
}
边栏推荐
- [Thesis reading | deep reading] role2vec:role based graph embeddings
- 【云原生】AI云开发平台——AI Model Foundry介绍(开发者可免费体验AI训练模型)
- Using virtual environments in jupyter notebook
- 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
- 实用调试技巧
- [operation] getting started with MySQL on May 23, 2022
- 解决navicat连接数据库遇到的问题
- (Reprinted) an article will take you to understand the reproducing kernel Hilbert space (RKHS) and various spaces
- [punch in - Blue Bridge Cup] day 1 --% 7F format output
- Mysql性能优化(5):主从同步原理与实现
猜你喜欢

Selenium environment installation, 8 elements positioning --01

Usage record of unity input system (instance version)

Radiant energy, irradiance and radiance

巧用 Bitmap 实现亿级海量数据统计

Buffer pool of MySQL notes

NER中BiLSTM-CRF解读score_sentence
![[punch in - Blue Bridge Cup] day 5 --- lower() small](/img/b5/21f51a7416c72c299cc59192a33b3a.jpg)
[punch in - Blue Bridge Cup] day 5 --- lower() small

【力扣刷题总结】数据库题目按知识点分类总结(持续更新/简单和中等题已完结)

Mysql性能优化(6):读写分离

深入浅出掌握grpc通信框架
随机推荐
如何利用FME 创建自己的功能软件
Semantic segmentation resources
深入浅出掌握grpc通信框架
EasyCVR部署服务器集群时,出现一台在线一台不在线是什么原因?
124 articles in total! Motianlun "high availability architecture" dry goods document sharing (including Oracle, mysql, PG)
Integrating viewbinding and viewholder with reflection
各位大佬,flink 1.13.6,mysql-cdc2.2.0,抽取上来的datetime(6)类
Hisense A7 ink screen mobile phone cannot be started
How to analyze and solve the problem of easycvr kernel port error through process startup?
How to use FME to create your own functional software
Is the largest layoff and salary cut on the internet coming?
Note: load the configuration file as a byte stream and get the resources in it
[punch in - Blue Bridge Cup] day 1 --% 7F format output
云原生入门+容器概念介绍
[Note] ab Test and Variance Analysis
[punch in - Blue Bridge Cup] day 4--------- split ('') cannot be used. There is a space after the last number of test cases. Split ()
A minimalist way to integrate databinding into activity/fragment
Redis is used in Windows system
Day 9 script and resource management
王爽-汇编语言 万字学习总结