1 条题解
-
0
C :
#include <stdio.h> int main() { int s,w,e,y; int n; scanf("%d",&n); for(s=1;s<=10;s++) { for(w=1;w<=20;w++) { for(e=1;e<=50;e++) { for(y=1;y<=100;y++) if(s*10+w*5+e*2+y==100&&s+w+e+y==n) printf("%d %d %d %d\n",s,w,e,y); } } } }C++ :
#include<iostream> #include<cstdio> using namespace std; int main(){ int n,i,j,k,a; scanf("%d",&n); for(i=1;i<n;i++) for(j=1;j<n-i;j++) for(k=1;k<n-j-i;k++){ if(i*9+j*4+k+n==100) printf("%d %d %d %d\n",i,j,k,n-i-j-k); } return 0; }Pascal :
program jco28; var a,b,c,d:longint; n:longint; begin readln(n); for a:=1 to 10 do begin if a>n then halt; for b:=1 to 20 do begin if a+b>n then continue; for c:=1 to 50 do begin if a+b+c>n then continue; for d:=1 to 100 do begin if a+b+c+d<>n then continue; if a*10+b*5+c*2+d=100 then writeln(a,' ',b,' ',c,' ',d); end; end; end; end; end.Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int i,j,k,l; for(i=1;i<10;i++){ for( j=1;j<18;j++){ for( k=1;k<43;k++){ for(l=1;l<84;l++){ if(i+j+k+l==n&&i*10+j*5+k*2+l*1==100){ System.out.print(i+" "); System.out.print(j+" "); System.out.print(k+" "); System.out.print(l+" "); System.out.println(); } } } } } } }
- 1
信息
- ID
- 1044
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者