小乐乐的班主任想统计一下班级里一共有多少人需要被请家长,三个成绩(语文,数学,外语)平均分低于60的将被请家长,小乐乐想编程帮助班主任算一下有多少同学被叫家长。
共n+1行
第一行,输入一个数n,代表小乐乐的班级中有n个同学。
在接下来的n行中每行输入三个整数代表班级中一个同学的三科成绩(语文,数学,外语),用空格分隔。
一行,一个整数,代表班级中需要被请家长的人数。
3 80 100 90 40 70 65 20 84 93
1
var n = readline()*1;
var counts = 0;
while(n--){
var p = readline().split(" ");
var total = 0;
for (i = 0;i < 3;i++) {
total += parseInt(p[i]);
}
if (total/3 < 60) counts++;
}
console.log(parseInt(counts)); 存在非法的输入
1
60 59 61
0
所以要加上if(n!=0),不然无法通过所有测试用例
import java.util.*;
public class Main
{
public static void main(String [] args)
{
Scanner sc=new Scanner(System.in);
while(sc.hasNextInt())
{
int n=sc.nextInt();
int count=0;
for(int i=0;i<n;i++)
{
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
int avg=(a+b+c)/3;
if(avg<60)
{
count++;
}
}
if(n!=0)
{
System.out.println(count);
}
}
}
}
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int count=0;
int a,b,c;
while(~scanf("%d%d%d",&a,&b,&c)){
if((a+b+c)/3<60 && a!=0){
count++;
}
}
printf("%d\n",count);
return 0;
}
测试案例有问题,将问题案例 a = 0 排除即可通过测试
number = int(input()) result = 0 for _ in range(number): list_score = list(map(int, input().split())) average = sum(list_score) / len(list_score) if average < 60: result = result + 1 print(result)
#include <stdio.h>
int main()
{
int n =0;
int i = 0;
int yu=0,shu=0,ying=0;
int x=0;
scanf("%d\n",&n);
for(i=0;i<n;i++)
{
scanf("%d %d %d\n",&yu,&shu,&ying);
if((yu+shu+ying)/3.0<60)
{
x=x+1;
}
}
printf("%d\n",x);
return 0;
}