zoukankan      html  css  js  c++  java
  • PAT---数字分类

    C++设置输出小数位的函数

    #include<iomanip>

    cout << setiosfalgs(ios::fixed)<<setprecision(2)<<2.119;

    #include<iostream> 
    #include<vector>
    #include<iomanip>
    
    using namespace std;
    
    int main()
    {
        int num;
        
        cin>>num;
        
        int *test=new int[num];
        int tmp=0;
        for(int i=0;i<num;i++)
            cin >> test[i];
        
        vector<int> A1,A2,A3,A4,A5;
        for(int i=0;i<num;i++)
        {
            tmp=test[i]%5;
            switch(tmp)
            {
                case 0:
                    if(test[i]%10==0)
                        A1.push_back(test[i]);
                    break;
                case 1:
                    A2.push_back(test[i]);
                    break;
                case 2:
                    A3.push_back(test[i]);
                    break;
                case 3:
                    A4.push_back(test[i]);
                    break;
                case 4:
                    A5.push_back(test[i]);
                    break;
                default :
                    break;
            }
        }
    
        double t_f=0.0;
        cout<<setiosflags(ios::fixed)<<setprecision(1);
        if(A1.size()==0)
            cout<<"N ";
        else
        {
            tmp=0;
            for(int i=0;i<A1.size();i++)
                if(A1[i]%2==0)
                    tmp+=A1[i];
            cout <<tmp<<" ";
        }    
        
        if(A2.size()==0)
            cout<<"N ";
        else
        {
            int k=-1;
            tmp=0;
            for(int i=0;i<A2.size();i++)
            {
                k=0-k;
                tmp+=A2[i]*k;
            }
            cout<<tmp<<" ";
        }    
        if(A3.size()==0)
            cout<<"N ";
        else
            cout <<A3.size()<<" ";
        if(A4.size()==0)
            cout<<"N ";
        else
        {
            tmp=0;
            for(int i=0;i<A4.size();i++)
                tmp+=A4[i];
            t_f=tmp*1.00/A4.size();
            cout<<t_f<<" ";
        }
        if(A5.size()==0)
            cout<<"N ";
        else
        {
            tmp=0;
            for(int i=0;i<A5.size();i++)
                if(A5[i]>tmp)
                    tmp=A5[i];
            cout<<tmp<<endl;
        }
        
        delete [] test;
        return 0;
    }
  • 相关阅读:
    HDU 2147 找规律博弈
    HDU 1564 找规律博弈
    寒假训练3解题报告 CodeForces #148
    HDU 1525 Euclid Game
    状态压缩DP总结
    HDU 1079 简单博弈
    CodeForces 159E
    codeforces 88E Interesting Game
    【poj2891-Strange Way to Express Integers】拓展欧几里得-同余方程组
    【poj1006-biorhythms】中国剩余定理
  • 原文地址:https://www.cnblogs.com/wujing-hubei/p/6426560.html
Copyright © 2011-2022 走看看