题解:P14495 [NCPC 2025] Arithmetic Adaptation

· · 题解

其实有一共只有三种情况。

  1. s=\pm999
  2. \begin{cases}a=999 \\b=s-999\end{cases}
  3. \begin{cases}a=-999 \\b=s+999\end{cases}
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    // 7~14:因为a不等于0,b不等于0,所以要特判 
    if (n == 999){
        cout<<1<<' '<<998;
        return 0;
    }
    if (n == -999){
        cout<<-1<<' '<<-998;
        return 0;
    }
    if (n - 999 > -1000){
        cout<<999<<' '<<n - 999;
    }
    else {
        cout<<-999<<' '<<n + 999;
    }
    return 0;
}