题解 | #记负均正II#

记负均正II

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

牛客前面一道的变式

#include <algorithm>
#include <iomanip>

using namespace std;

int main() {
        int temp,negative=0,positive=0;
        double sum=0;
           while(cin>>temp){
            if(temp<0)negative++;
            else if(temp>=0) {
                sum+=temp;
                positive++;
            }
            
           }
        cout<<negative<<endl;
        if(positive)cout<<fixed<<setprecision(1)<<sum/positive<<endl;
        else cout<<fixed<<setprecision(1)<<0.0<<endl;
        
        
    }


全部评论

相关推荐

双尔:你就写拥有ai开发经历,熟练运用提示词,优化ai,提高ai回答质量
点赞 评论 收藏
分享
11-03 16:42
井冈山大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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