求1~n整数中1出现的次数

下面以1~13为例,其中得到1,10,11,12,13,其中1出现的次数为6;

n的值可以自行定义。 

#include
#include
#include
using namespace std;
int main()
{
	//求1~n整数中1出现的次数 
	std::stringstream stream;
	std::string result;
	int n=13;
	int count=0;
	while(n>0)
	{
		stream<>result;//从stream中抽取前面插入的int值
		//std::cout<

 

你可能感兴趣的:(c++)