华为初级——(练习用)挑7

来源:互联网 发布:淘宝女装代理哪家好 编辑:程序博客网 时间:2024/05/22 00:09

源程序:

#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)这条很好用的语句。


0 0
原创粉丝点击