1 条题解
-
0
P76041 加法小助手 — 题解
专题: 函数
适用题目: 新生 OJ 本地题包中的 P76041,不要直接用于外站同名题。解题思路
将两数相加的操作封装到
add(a,b),在每组输入后调用它并输出返回值。复杂度
每组时间 。
易错点
强调函数声明、实参、形参、返回值,而不是把所有代码直接写在
main。C11 参考程序
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include <limits.h> int add(int a,int b){return a+b;} int main(void) { int t;scanf("%d",&t); while(t--){int a,b;scanf("%d%d",&a,&b);printf("%d\n",add(a,b));} return 0; }C++17 参考程序
#include <bits/stdc++.h> using namespace std; int add(int a, int b) { return a + b; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int t; cin >> t; while (t--) { int a, b; cin >> a >> b; cout << add(a, b) << '\n'; } return 0; }
题解建议设置为训练结束后开放。普通判题无法验证是否实际使用指定函数或 STL。
- 1
信息
- ID
- 1810
- 时间
- 2000ms
- 内存
- 256MiB
- 难度
- 1
- 标签
- 提交数
- 2
- 已通过
- 2
- 上传者