"Основи на програмирането със C++"/Глава 9.2 Задача: бикове и крави
https://cpp-book.softuni.bg/chapter-09-problems-for-champions-part-2.html
Задачата я решавам както е показано в упътването, но не ми се получава. Пишете ми къде греша.
int n, bullNumb, cowNumb;
cin>>n>>bullNumb>>cowNumb;
int counterCows=0, counterBulls=0, counter=0;
for (int i=1; i<=9; i++){
for (int j=1; j<=9; j++){
for (int k=1; k<=9; k++){
for (int l=1; l<=9; l++){
int thousads, hundreds, tens, units;
thousads=n/1000;
hundreds=(n%1000)/100;
tens=(n%100)/10;
units=n%10;
int digitToCheck1=i;
int digitToCheck2=j;
int digitToCheck3=k;
int digitToCheck4=l;
if (digitToCheck1==thousads){
counterBulls++;
digitToCheck1=-2;
thousads=-1;
}
if (digitToCheck2==hundreds){
counterBulls++;
digitToCheck2=-2;
hundreds=-1;
}
if (digitToCheck3==tens){
counterBulls++;
digitToCheck3=-2;
tens=-1;
}
if (digitToCheck4==units){
counterBulls++;
digitToCheck4=-2;
units=-1;
}
if (digitToCheck1==hundreds){
counterCows++;
hundreds=-3;
}else if (digitToCheck1==tens){
counterCows++;
tens=-3;
}else if (digitToCheck1==units){
counterCows++;
units=-3;
}
if (digitToCheck2==thousads){
counterCows++;
thousads=-4;
}else if (digitToCheck2==tens){
counterCows++;
tens=-4;
}else if (digitToCheck2==units){
counterCows++;
units=-4;
}
if (digitToCheck3==thousads){
counterCows++;
thousads=-5;
}else if (digitToCheck3==hundreds){
counterCows++;
hundreds=-5;
}else if (digitToCheck3==units){
counterCows++;
units=-5;
}
if (digitToCheck4==thousads){
counterCows++;
thousads=-6;
}else if (digitToCheck4==hundreds){
counterCows++;
hundreds=-6;
}else if (digitToCheck4==tens){
counterCows++;
tens=-6;
}
if (counterBulls==bullNumb&&counterCows==cowNumb){
cout<<i<<j<<k<<l<<" ";
counter++;
}
}
}
}
}
if (counter==0){
cout<<"No"<<endl;
}
Много благодаря за помощта!