{"title":"C++ 统计页码中数字出现次数 - 入门级算法题","description":"本题要求你统计一本书从 1 到 N 的页码中,每个数字(0 到 9)分别出现了多少次。这是一个入门级的算法题,适合初学者练习数组和循环的使用。","keywords":"C++, 算法, 入门, 统计, 页码, 数字, 循环, 数组","content":"#include <iostream>\n#include <vector>\nusing namespace std;\n\nint main() {\n int N;\n cin >> N;\n \n vector<int> count(10, 0);\n\n for (int i = 1; i <= N; i++) {\n int num = i;\n while (num > 0) {\n int digit = num % 10;\n count[digit]++;\n num /= 10;\n }\n }\n\n for (int i = 0; i < 10; i++) {\n cout << count[i] << endl;\n }\n\n return 0;\n}\n"}

C++ 统计页码中数字出现次数 - 入门级算法题

原文地址: http://www.cveoy.top/t/topic/qsB7 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录