刚学不等式的蒟蒻求助
查看原帖
刚学不等式的蒟蒻求助
1028403
封禁用户楼主2024/7/10 09:59

rt,WA 35 pts. 可能写的有点麻烦。

#include <iostream>
using namespace std;

string Turn(int x) {
    if (x == 1) return ">=";
    if (x == 2) return ">";
    if (x == 3) return "<=";
    if (x == 4) return "<";
}

string Rev(string s) {
    if (s == ">") return "<";
    if (s == "<") return ">";
    if (s == ">=") return "<=";
    if (s == "<=") return ">=";
}

int main() {
    int n;
    char c;
    cin >> n >> c;
    int mx = -1e9, mn = 1e9;
    int posa = 0, posb = 0;
    bool big = false, small = false;
    for (int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        if (s.find(">=") != string::npos) {
            int x = 0;
            if (s[3] == '-') x = -stoi(s.substr(4));
            else x = stoi(s.substr(3));
            if (x > mx) mx = x, posa = 1;
            big = true;
        } else if (s.find(">") != string::npos) {
            int x = 0;
            if (s[2] == '-') x = -stoi(s.substr(3));
            else x = stoi(s.substr(2));
            if (x > mx) mx = x, posa = 2;
            big = true;
        } else if (s.find("<=") != string::npos) {
            int x = 0;
            if (s[3] == '-') x = -stoi(s.substr(4));
            else x = stoi(s.substr(3));
            if (x < mn) mn = x, posb = 3;
            small = true;
        } else if (s.find("<") != string::npos) {
            int x = 0;
            if (s[2] == '-') x = -stoi(s.substr(3));
            else x = stoi(s.substr(2));
            if (x < mn) mn = x, posb = 4;
            small = true;
        }
    }
    if (big && !small) cout << c << Turn(posa) << mx << "\n";
    else if (!big && small) cout << c << Turn(posb) << mn << "\n";
    else {
        if (mx > mn) cout << "No Answer!\n";
        else cout << mx << Rev(Turn(posa)) << c << Turn(posb) << mn << "\n";
    }
    return 0;
}
2024/7/10 09:59
加载中...