题解 | #记负均正II#

记负均正II

http://www.nowcoder.com/practice/64f6f222499c4c94b338e588592b6a62

就是简单的数据处理,不明白为啥这个题的难度是较难

#include <stdio.h>

int main(void)
{
    float num;
    int count1 = 0;
    int count2 = 0;
    int array[1000];
    int i = 0;
    float re = 0;
    while(scanf("%f", &num) != EOF)
    {
        if(num < 0)
        {
            count1++;
        }
        else if(num >= 0)
        {
            re += num;
            count2++;
        }
    }

    printf("%d\n", count1);
    if(count2 == 0)    
        printf("%.1f",(float)count2);
    else if(count2 > 0)    
        printf("%.1f\n", (float)(re / count2));

    return 0;
}
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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