1 条题解
-
0
三位数的数字和 题解
解题思路
枚举所有三位数
100到999。分别取出百位、十位和个位,判断三位数字之和是否等于s。参考代码
#include<bits/stdc++.h> using namespace std; int main() { int s; cin >> s; int cnt = 0; for (int i = 100; i <= 999; i++) { int a = i / 100; int b = i / 10 % 10; int c = i % 10; if (a + b + c == s) { cout << i << endl; cnt++; } } if (cnt == 0) { cout << "None" << endl; } cout << "Count: " << cnt << endl; return 0; }
- 1
信息
- ID
- 4883
- 时间
- 1000ms
- 内存
- 64MiB
- 难度
- 10
- 标签
- 递交数
- 2
- 已通过
- 2
- 上传者
粤公网安备44195502000195号