#include<iostream>
using namespace std;
bool check(int n,int d){
while(n > 0){
int num = n % 10;
if(num == d){
return true;
}
n = n / 10;
}
}
int main(){
int n,d;
cin>>n>>d;
if(check(n,d) == false){
cout<<"false";
}else{
cout<<"true";
}
return 0;
}
判断是否包含
本文介绍了一个C++函数check(n, d),用于检查整数n的每一位是否等于给定的数字d。通过除法和取余操作,函数逐位遍历并判断。当n不包含d时,返回false,否则返回true。

被折叠的 条评论
为什么被折叠?



