#include <stdio.h>
#include <iostream>
#include <fstream>
using namespace std;
int gaseste_cifra(int x, int c){
int k=0;
bool check=true;
while(check){
if(x/10==0){
if(x%10==c){
k++;
}
check=false;
} else {
if(x%10==c){
k++;
}
x=x/10;
}
}
return k;
}
int main()
{
int x, c, nr, cifraControl=0;
cout<<"Dati x:"; cin>>x;
cout<<"Dati c:"; cin>>c;
cout<<gaseste_cifra(x,c);
cout<<"\nDati nr:"; cin>>nr;
ofstream controlF("control.out");
for(int i=0; i<=9; i++){
int aparitii=gaseste_cifra(nr,i);
controlF<<aparitii;
cifraControl+=aparitii*i;
if(cifraControl>=10){
int rest, cat;
rest=cifraControl%10;
cat=cifraControl/10;
cifraControl=rest+cat;
}
}
controlF<<"\n"<<cifraControl;
controlF.close();
return 0;
}