1 条题解
-
0
【例6.2】捡石头
解题思路
已有三块石头重 a+b+c,第四块应为 20-a-b-c。
正确性说明
四块总重减去已知三块重量,剩下的正是未知第四块重量。
易错点
不能把已有重量直接输出。
复杂度
本题规模固定,时间 O(1),额外空间 O(1)。
参考代码(C++11)
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int a, b, c; cin >> a >> b >> c; cout << 20 - a - b - c << "\n"; return 0; }
- 1