1 条题解
-
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; } } } } }Pascal :
var x,y,z:longint; begin for x:=1 to 19 do for y:=1 to 31 do for z:=1 to 92 do if (x+y+z=100) and (x*5+y*3+z/3=100) then writeln(x,' ',y,' ',z); end.Java :
public class Main { public static void main(String[] args) { for (int x = 3; x < 100; x = x + 3) { for (int g = 1; g < 20; g++) { for (int m = 1; m < 33; m++) { if (x + g + m == 100 && x / 3 + 5 * g + 3 * m == 100) { System.out.println( g + " " + m + " " + x); } } } } } }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
信息
- ID
- 21
- 时间
- 1000ms
- 内存
- 512MiB
- 难度
- 10
- 标签
- 递交数
- 2
- 已通过
- 1
- 上传者