2012/02/17

[zerojudge] a148 You Cannot Pass?!

題目:https://zerojudge.tw/ShowProblem?problemid=a148
說明:將讀取的 stdin 分成兩部分,計算第二個數之後的總和除上第一個數。

Java 版
import java.util.Scanner;
 
public class A148 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String [] str = in.nextLine().split(" ");
            double sum = 0;
            for(int a = 1; a <= str.length-1; a++){
                sum += Double.parseDouble(str[a]);
            }
            double avg = sum / Double.parseDouble(str[0]);
            if(avg <= 59){
                System.out.println("yes");
            }
            else{
                System.out.println("no");
            }
        }
    }
}
Python 版 (2022.07)
while True:
    try:
        a = input().split(' ')
        s = map(int, a[1:])
        r = sum(s) / int(a[0])
        if r <= 59:
            print('yes')
        else:
            print('no')
    except:
        break

沒有留言:

張貼留言