题解 | #记负均正#

记负均正

http://www.nowcoder.com/practice/6abde6ffcc354ea1a8333836bd6876b8

#include<stdio.h>
#include<math.h>
int main()
{
    int num;
    int a[1000];
    while(scanf("%d",&num)!=EOF)
    {
        int count = 0;
        int countint =0;
        float sum = 0;
        for(int i =0;i<num;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]<0)
            {
                count++;
            }
            if(a[i]>0)
            {
                countint++;
                sum+=a[i];
            }
        }
        printf("%d %0.1f\n",count,sum/countint);
    }
}
全部评论
if(countint>0) { printf("%d %0.1f\n",count,sum/countint); } else { printf("%d 0.0",count); }
6 回复 分享
发布于 2022-05-22 18:31
自己拿去跑一遍再发出来
3 回复 分享
发布于 2022-08-24 16:01 湖北
我没查到
点赞 回复 分享
发布于 2023-05-01 23:52 陕西
countint>0?sum/countint:0 这个是什么意思 用了什么知识?
点赞 回复 分享
发布于 2023-05-01 23:52 陕西
printf("%d %0.1f\n",count,countint>0?sum/countint:0);给你改了一下这里
点赞 回复 分享
发布于 2023-02-15 22:40 广东

相关推荐

06-26 17:24
已编辑
宁波大学 Java
迷失西雅图:别给,纯kpi,别问我为什么知道
点赞 评论 收藏
分享
05-26 10:24
门头沟学院 Java
qq乃乃好喝到咩噗茶:其实是对的,线上面试容易被人当野怪刷了
找工作时遇到的神仙HR
点赞 评论 收藏
分享
评论
6
1
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务