用 C++ 語言確定給定點位於內部的矩形的座標
在本文中,我們將討論一個程式,以便找到矩形的座標
且給定點位於內部。
為此,我們將提供一些座標點。我們的任務是找到最小的矩形,使所有點位於其內部,並且其邊平行於座標軸。
示例
#include <bits/stdc++.h>
using namespace std;
//calculating the coordinates of smallest rectangle
void print_rectangle(int X[], int Y[], int n){
//finding minimum and maximum points
int Xmax = *max_element(X, X + n);
int Xmin = *min_element(X, X + n);
int Ymax = *max_element(Y, Y + n);
int Ymin = *min_element(Y, Y + n);
cout << "{" << Xmin << ", " << Ymin << "}" << endl;
cout << "{" << Xmin << ", " << Ymax << "}" << endl;
cout << "{" << Xmax << ", " << Ymax << "}" << endl;
cout << "{" << Xmax << ", " << Ymin << "}" << endl;
}
int main(){
int X[] = { 4, 3, 6, 1, -1, 12 };
int Y[] = { 4, 1, 10, 3, 7, -1 };
int n = sizeof(X) / sizeof(X[0]);
print_rectangle(X, Y, n);
return 0;
}輸出
{-1, -1}
{-1, 10}
{12, 10}
{12, -1}
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP