题解 | #记负均正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;
        
        
    }


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务