ACM 競程最基礎的 A+B 題,兩種常見實作:
#include <stdio.h>
int main()
{
int a, b;
while (scanf("%d %d", &a, &b) == 2)
{
printf("%d\n", a + b);
}
return 0;
}
適用於多組測試資料,直到 EOF 結束。
#include <stdio.h>
int main()
{
int a = 3, b = 4;
printf("%d\n", a + b);
return 0;
}
僅供快速驗證邏輯,實際提交需採方式一。
提醒:main() 應回傳 int,避免使用 void main()。