华为0基础——(练习用)挑7

源程序:

#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;char buffer[6];
	int count=0;
	int len;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		if((i%7)==0)count++;
		else 
		{
			itoa(i,buffer,10);
			len=strlen(buffer);
			for(int j=0;j<len;j++)
			{
				if(buffer[j]=='7')
				{ 
					count++;
					break;
				}
			}
		}
	}
	cout<<count<<endl;
	return 0;
}

执行结果:


总结:So easy~没话说哈~我的程序是将不是7的倍数的那些数转换为字符串。再查找字符串中是否含有7。所以中间用到了itoa(i,buffer,10)这条非常好用的语句。


原文地址:https://www.cnblogs.com/bhlsheji/p/5115543.html