当前位置:   article > 正文

西安交通大学915-2019-编程1_西安交通大学2019年915真题

西安交通大学2019年915真题

题目描述:

在这里插入图片描述

解题思路:

存储 + 遍历更新

代码实现:

#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;
} 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/867306
推荐阅读
相关标签
  

闽ICP备14008679号