29 lines
641 B
C
29 lines
641 B
C
#include <stdio.h>
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
bool checkDigits(int chicken, int rabbit) {
|
|
bool digits[6] = {0};
|
|
int num = chicken*1000 + rabbit;
|
|
while (num > 0) {
|
|
if (num % 10 > 6 || digits[num % 10]) {
|
|
return false;
|
|
}
|
|
else {
|
|
digits[num % 10] = true;
|
|
num /= 10;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
int main() {
|
|
int count = 50;
|
|
for (count = 50; count < 250; count++) {
|
|
if (checkDigits(count * 2, count * 4)) {
|
|
printf("There are %d chickens and rabbits. %d chicken legs, %d rabbit legs.", count, count*2, count*4);
|
|
}
|
|
}
|
|
return 0;
|
|
} |