赞
踩
存储 + 遍历更新
#include <iostream> using namespace std; struct Pair { int x; int y; }; const int N = 100; Pair arr[N]; int idx = 0; namespace lsc { void min(Pair& mi, Pair& x) { if (x.x < mi.x || x.y < mi.y) { mi = x; } } void max(Pair& mx, Pair& x) { if (x.x > mx.x || x.y > mx.y) { mx = x; } } } void Solution() { Pair mi = {INT_MAX, INT_MAX}; Pair mx = {INT_MIN, INT_MIN}; for (int i = 0; i < idx; i++) { lsc::max(mx, arr[i]); lsc::min(mi, arr[i]); } char s[128] = {0}; char t[128] = {0}; sprintf(s, "the index of left down is (%d, %d)", mi.x, mi.y); sprintf(t, "the index of right up is (%d, %d)", mx.x, mx.y); cout << s << endl; cout << t << endl; } int main() { cout << "please input the location of point:" << endl; while (1) { Pair p; cin >> p.x >> p.y; if (p.x == 0 && p.y == 0) { break; } arr[idx++] = p; } Solution(); return 0; }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。