#include <iostream>
using namespace std;
int apcif(int n, int c)
{//numarul de aparitii ale lui c in n
if(n<=9) return n==c;
else if(n%10==c) return apcif(n/10,c)+1;
else return apcif(n/10,c);
}
int dist(int n, int c)
{//numara cifrele distincte ale lui n
if(c==-1) return 0;
else if(apcif(n,c)) return dist(n,c-1)+1;
else return dist(n,c-1);
}
int main()
{
int n;
cin>>n;
cout<<dist(n,9);
return 0;
}
sau
#include <iostream>
using namespace std;
int apcif(int n, int c)
{//verific daca c apare in n
if(n<=9) return n==c;
else if(n%10==c) return 1;
else return apcif(n/10,c);
}
int nrdist(int n)
{//numara cifrele distincte ale lui n
if(n==0) return 0;
else if(apcif(n/10,n%10)==0) return nrdist(n/10)+1;
else return nrdist(n/10);
}
int main()
{
int n;
cin>>n;
cout<<nrdist(n);
return 0;
}
|