zoukankan      html  css  js  c++  java
  • 1012 数字分类 (20 分)

    #include <iostream>
    #include <string>
    #include <iomanip>
    using namespace std;
    int main(){
        double sum4 = 0.0;
        int n, t, k = -1, cnt = 0, cnt2 = 0, max = 0, sum1 = 0, sum2 = 0, sum3 = 0;
        cin >> n;
        while (n--){
            cin >> t;
            if (t % 10 == 0)
                sum1 += t;
            else if (t % 5 == 1){
                k = -k;
                sum2 += t * k;
                cnt2++;  // 这个地方需要注意,若果没有这个计数器的话答案总是WA, 不知道为啥
            }
            else if (t % 5 == 2)
                sum3++;
            else if (t % 5 == 3){
                sum4 += t;
                cnt++;
            }
            else if (t % 5 == 4){
                if (max < t)
                    max = t;
            }
        }
        if (cnt > 0) sum4 /= cnt;
    
        if (sum1 == 0) cout << "N" << ' ';
        else cout << sum1 << ' ';
    
        if (cnt2 == 0) cout << "N" << ' ';
        else cout << sum2 << ' ';
    
        if (sum3 == 0) cout << "N" << ' ';
        else cout << sum3 << ' ';
    
        if (sum4 == 0.0) cout << "N" << ' ';
        else cout << fixed << setprecision(1) << sum4 << ' ';
    
        if (max == 0) cout << "N" << endl;
        else cout << max << endl;
    
        return 0;
    }
  • 相关阅读:
    链表数据-PHP的实现
    关于go的init函数
    socket小计
    很随笔
    go获取当前项目下所有依赖包
    关于synergy的问题
    二叉树的最大路径和
    大数求和
    重载<<运算符第二个参数必须加上const
    表达式求值
  • 原文地址:https://www.cnblogs.com/Hk456/p/10720713.html
Copyright © 2011-2022 走看看