pangfengliu / programmingtasks

programming tasks from my courses
68 stars 17 forks source link

Chicken, Rabbit and Crab #215

Open sinmaplewing opened 10 years ago

sinmaplewing commented 10 years ago

Task Description

寫一個程式來解決一個問題。有雞、兔子和螃蟹在同一個籠子裡。現給定這些動物的總數(s)、動物腳的總數(f)及動物尾巴的總數(t),(0<=s, f, t<=2^31-1) 請計算兔子、雞、螃蟹的數量。如果給定的數字不可能有解,程式應該輸出 0。

Sample input :

9 48 5

Sample output :

2
3
4

Sample input :

9 48 20

Sample output :

0

Test Data

You can download the test data (which JudgeGirl uses) from here.

sunnyhsu9051 commented 8 months ago

include

int main(){ //rabbit+chicken+crab=num; //4rabbit + 2chicken + 8crab= legs //chicken + rabbit= tail int num,legs,tail; int rabbit,chicken,crab; scanf("%d",&num); scanf("%d",&legs); scanf("%d",&tail); crab = num - tail; rabbit=legs - 2num - 4crab; chicken=tail - rabbit; if (rabbit < 0 || chicken <0 || crab <0) printf("0"); else printf("%d %d %d",rabbit,chicken,crab); return 0; }