P14495 [NCPC 2025] Arithmetic Adaptation

· · 题解

1. 题目分析

阅读理解题。

设 a+b=s 且符合题意,分情况讨论。

因为 s 在三位数以内,所以这样也可以限制 a 和 b 在三位数以内。

但考虑情况不完整,当 s=-1 或 s=1 时,上述方案并不成立,这时我们不妨特判,选择你喜欢的数字输出就好了。

2. 代码

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int s;
    scanf("%d",&s);
    if(s==1)printf("-1 2\n");
    else if(s==-1)printf("1 -2\n");
    else if(s>=0)printf("%d %d\n",1,s-1);
    else printf("%d %d\n",-1,s+1);
    return 0;
}