- 【练8-3】最小值
666
- @ 2026-1-6 19:49:23
#include #include #include #include
using namespace std;
int main() {
string n;
cin >> n;
int min_diff = INT_MAX;
const int target = 753;
for (int i = 0; i <= n.length() - 3; ++i) {
string three_digits_str = n.substr(i, 3);
int three_digits = stoi(three_digits_str);
int diff = abs(three_digits - target);
if (diff < min_diff) {
min_diff = diff;
}
}
cout << min_diff << endl;
return 0;
}
0 条评论
目前还没有评论...
信息
- ID
- 685
- 时间
- ms
- 内存
- MiB
- 难度
- 5
- 标签
- (无)
- 递交数
- 109
- 已通过
- 39
- 上传者