九度oj--1002和1045

题目1002:Grading

题目描述:
Grading hundreds of thousands of Graduate Entrance Exams is a hard work. It is even harder to design a process to make the results as fair as possible. One way is to assign each exam problem to 3 independent experts. If they do not agree to each other, a judge is invited to make the final decision. Now you are asked to write a program to help this process.
For each problem, there is a full-mark P and a tolerance T(

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        int p,t,g1,g2,g3,gj,max;
        double grade;
        while(cin.hasNext()){
           p = cin.nextInt();
           t = cin.nextInt();
           g1 = cin.nextInt();
           g2 = cin.nextInt();
           g3 = cin.nextInt();
           gj = cin.nextInt();
           grade = 0.0;
           if(Math.abs(g1 - g2) <= t)
                grade = (double)(g1 + g2)/2;
           else if(Math.abs(g1-g3) <= t && Math.abs(g2-g3) <= t){
                max = g1;
                if(g2 > max)
                    max = g2;
                if(g3 > max)
                    max = g3;
                grade = max;    
            }
            else if(Math.abs(g1 - g3) <= t)
                grade = (double)(g1 + g3)/2;
            else if(Math.abs(g2 - g3) <= t)
                grade = (double)(g2 + g3)/2;
            else
                grade = gj;
            System.out.printf("%.1f\n", grade);

        }
    }
}

被这个题折磨了好久,一直都是Wrong Answer还找不到错误,最后发现又是不仔细,只注意了在最后一种情况下求平均数时转换double,没有注意到第一种情况也求了平均数,忘记了转换类型而一直出错。

题目1045:百鸡问题

题目描述:
用小于等于n元去买100只鸡,大鸡5元/只,小鸡3元/只,还有1/3元每只的一种小鸡,分别记为x只,y只,z只。编程求解x,y,z所有可能解。
输入:
测试数据有多组,输入n。
输出:
对于每组输入,请输出x,y,z所有可行解,按照x,y,z依次增大的顺序输出。
样例输入:
40
样例输出:
x=0,y=0,z=100
x=0,y=1,z=99
x=0,y=2,z=98
x=1,y=0,z=99

import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner cin = new Scanner(System.in);
        int i,j,k,n,sum;
        //double sum;
        while(cin.hasNext()){
            n = cin.nextInt();
            for(i = 0 ; i <= n/5 ; i++){
                for(j = 0 ; j <= n/3; j++){
                    sum = n - 5*i - 3*j;
                    k = sum * 3;
                    if( (i + j + k) >= 100){
                        k = 100 - i - j;
                        System.out.printf("x=" + i + ",y=" + j + ",z=" + k + "\n");    
                    }
                }
            }
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值