1 solutions
-
0
C :
#include<stdio.h> void main() { int cock=0; //公鸡的数量 公鸡5元一只 int hen=0; //母鸡的数量 母鸡3元一只 int chick=0; //小鸡的数量 小鸡1元三只 for(cock=1;cock<20;cock++) //100块最多买20只公鸡 { for(hen=1;hen<33;hen++) //100块最多买33只母鸡 { chick=100-cock-hen; if(5*cock+3*hen+chick/3==100 && chick%3==0) { printf("%d %d %d\n",cock,hen,chick); } } } return 0; }C++ :
#include <iostream> #include <iomanip> #include <cmath> using namespace std; int main(){ int a,b,c; for(a=1;a<=98;a++){ for(b=1;b<=98;b++){ for(c=1;c<=98;c++){ if(a*5+b*3+c/3==100&&a+b+c==100&&c%3==0){ cout<<a<<" "<<b<<" "<<c<<endl; } } } } }Python :
for i in range(1, 100//5 + 1): for j in range(1,100 // 3): if 100 - i * 5 - j * 3 >= 1 and i + j + 3 * (100 - i * 5 - j * 3) == 100: print(i,j,3 * (100 - i * 5 - j * 3))
- 1
Information
- ID
- 1210
- Time
- 1000ms
- Memory
- 16MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By