博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
first day~
阅读量:7100 次
发布时间:2019-06-28

本文共 1454 字,大约阅读时间需要 4 分钟。

it's been a long time without practicing~ almost everything about the C programming language.

learn today: 1/ read the problem carefully.

                  2/no blank between two input (scanf(“%d %d", &a, &b);

prac: 2001()

计算两点间的距离

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 95055    Accepted Submission(s): 36510

Problem Description
输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。
 
Input
输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开。
 
Output
对于每组输入数据,输出一行,结果保留两位小数。
 
Sample Input
0 0 0 1 0 1 1 0
 
Sample Output
1.00 1.41
 
Author
lcy
 
Source
 
Recommend
JGShining   |   We have carefully selected several similar problems for you:            
 
 first try: output limit exceeded
 
#include
#include
int main(){ int x1, y1, x2, y2; double result; while(scanf("%d %d %d %d", &x1, &y1, &x2, &y2)!=EOF){ result = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1)); printf("%.2f\n", result); } return 0;}

why?:题目的输入格式中明确说明了每组测例的输入是4个实数,而不是4个整数。scanf("%d", &n);这样的写法,在输入中有非数字和空格的字符出现时,读入会失败,但不报错,也不会跳过失败处的字符。所以楼主的程序在遇到第一个小数点的时候就一直重复输入最后一次正确读入的测例的结果了,最终造成输入超限。

 

second try: accepted

#include
#include
int main(){ double x1, y1, x2, y2, result; while(scanf("%lf%lf%lf%lf", &x1, &y1, &x2, &y2)!=EOF){ result = sqrt((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1)); printf("%.2lf\n", result); } return 0;}

 

转载于:https://www.cnblogs.com/comeonleo/p/3883865.html

你可能感兴趣的文章
关于前端 - 收藏集 - 掘金
查看>>
javaScript设计模式系列(一) 接口
查看>>
Vue的数据绑定部分的简要过程解释
查看>>
kubectl 搭建
查看>>
网络请求 - 收藏集 - 掘金
查看>>
好用的项目初始化工具SCION升级啦!
查看>>
Android敲门砖 - 收藏集 - 掘金
查看>>
[译] npm, yarn以及pnpm的不同之处
查看>>
通过Atlas实现MySQL读写分离
查看>>
JMessage Android 端开发详解
查看>>
你想不到的最简单php操作MySQL
查看>>
用 vue2 和 webpack 快速建构 NW.js 项目(2)
查看>>
LeetCode 31_Next Permutation
查看>>
2018 re:Invent回顾篇:前线开发者眼中AWS的创新版图
查看>>
GitHub Checks API帮助应用实现进一步的持续集成
查看>>
滴滴进入寒冬期,将裁员2000人
查看>>
埃隆·马斯克:比特币拥有着“极为出色”的结构,而纸质货币终将消失
查看>>
一行代码迁移TensorFlow 1.x到TensorFlow 2.0
查看>>
架构周报:十亿级红包的平台架构揭秘
查看>>
京东构建了全球最大的Kubernetes集群,没有之一
查看>>