Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
80509 sh25_huangse 数1的个数 C++ 通过 0 MS 244 KB 468 2026-01-04 15:19:32

Tests(1/1):


#include <iostream> using namespace std; int main() { int n; cin >> n; int totalOnes = 0; // 统计总个数 for (int i = 1; i <= n; i++) { int num = i; // 临时变量,用于分离各位 while (num > 0) { if (num % 10 == 1) { // 检查个位是否为1 totalOnes++; } num /= 10; // 去掉个位 } } cout << totalOnes << endl; return 0; }


测评信息: