zoukankan      html  css  js  c++  java
  • Openjudge-计算概论(A)-点与正方形的关系

    描述:

    有一个正方形,四个角的坐标(x,y)分别是(1,-1),(1,1),(-1,-1),(-1,1),x是横轴,y是纵轴。写一个程序,判断一个给定的点是否在这个正方形内。输入输入坐标x,y输出yes或者no样例输入

    3 4
    1 1
    0 0

    样例输出

    no
    yes
    yes

    提示

    提示1:

    系统的测试文件中数据有很多组,因此同学们在程序里要写循环读取数据并判断是否读完文件的代码。
    如果不知道如何处理,可以参考下面的两个模板:

    C++这样写:

    while(cin>>x>>y)
    {
      判断x,y是否在正方形里的代码
    }

    C这样写:

    while(scanf(%x %y",&x,&y)!=EOF)
    {
      判断x,y是否在正方形里的代码
    }

    提示2:

    输出结果时,必须加上换行符endl(C++语言)或 (c语言)。不然会报输出格式错误。

    提示3:

    要选对编程语言。如果程序是用C++语法写的,就不能在language里选c。会报编译错误。

    例子:

    比如说编号为1000的练习题,按以上要求的格式写出来的标准答案如下:

     1 #include <iostream>
     2 using namespace std;
     3 int main()
     4 {
     5     int a,b;
     6     while(cin>>a>>b)
     7     {
     8         cout<< a+b << endl;
     9     }
    10     return 0;
    11 }

    思路:既然题目中的提示都给了这么清楚了,不解释(偷懒的节奏.......)

    代码如下:

     1 #include<stdio.h>
     2 int main()
     3 {
     4   float x,y;  
     5   while(scanf("%f%f",&x,&y)!=EOF)
     6   {
     7       if(x<=1.0&&x>=-1.0&&y<=1.0&&y>=-1.0)
     8       printf("yes
    ");
     9       else
    10       printf("no
    ");
    11   }
    12   return 0;
    13 }
    我不怕千万人阻挡,只怕自己投降…
  • 相关阅读:
    JavaScript
    94.Binary Tree Inorder Traversal
    144.Binary Tree Preorder Traversal
    106.Construct Binary Tree from Inorder and Postorder Traversal
    105.Construct Binary Tree from Preorder and Inorder Traversal
    90.Subsets II
    78.Subsets
    83.Merge Sorted Array
    80.Remove Duplicates from Sorted Array II
    79.Word Search
  • 原文地址:https://www.cnblogs.com/geek-007/p/4294531.html
Copyright © 2011-2022 走看看