Run ID Author Problem Lang Verdict Time Memory Code Length Submit Time
80509 sh25_huangse 数1的个数 C++ Accepted 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; }


Judgement Protocol: