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

    #include<iostream>
    using namespace std;
    int main()
    {
    	int N = 0;
    	int arry[10000] = { 0 };
    	int count_A1 = 0,flag=1,count_A2=0,count_A3=0,count_A4=0,count_A5=0;//A2的模式切换标志 ,为0,:相减,为1:相加
    	int sum_A2 = 0;
    	double sum_A4 = 0;
    	int max_A5 = 0;
    	cin >> N;
    	while (N > 1000 || N < 0)
    	{
    		cin >> N;
    	}
    	for (int i = 0; i < N; i++)
    	{
    		cin >> arry[i];
    	}
    	//能被5整除的数字中有偶数的和
    	for (int i = 0; i < N; i++)
    	{
    		//A1的判断
    		if (((arry[i] % 5) == 0) && ((arry[i] % 2) == 0))
    		{
    			count_A1 += arry[i];
    		}
    		//A2的判断
    		if ((arry[i] % 5) == 1 && flag)
    		{
    			sum_A2 += arry[i];
    			flag = 0;
    			count_A2++;
    		}
    		else if ((arry[i] % 5) == 1 && !flag)
    		{
    			sum_A2 -= arry[i];
    			flag = 1;
    			count_A2++;
    		}
    		//A3的判断
    		if ((arry[i] % 5) == 2)
    		{
    			count_A3++;
    		}
    		//A4的判断
    		if ((arry[i] % 5) == 3)
    		{
    			sum_A4 += arry[i];
    			count_A4++;
    		}
    		//A5的判断
    		if (arry[i] >= max_A5&&(arry[i]%5)==4)
    		{
    			max_A5 = arry[i];
    			count_A5++;
    		}
    
    	}
    	//A1的输出
    	if (count_A1 == 0)
    	{
    		cout << 'N';
    		cout << " ";
    	}
    	else
    	{
    		cout << count_A1 << " ";
    	}
    	//A2的输出
    	if (count_A2 == 0)
    	{
    		cout << 'N';
    		cout << " ";
    	}
    	else
    	{
    		cout << sum_A2 << " ";
    	}
    	//A3的输出
    	if (count_A3 == 0)
    	{
    		cout << 'N';
    		cout << " ";
    	}
    	else
    	{
    		cout << count_A3 << " ";
    	}
    	//A4的输出
    	if (count_A4 == 0)
    	{
    		cout << 'N';
    		cout << " ";
    	}
    	else
    	{
    		double avg = 0;
    		avg = sum_A4 / count_A4;
    		avg = (int)(avg * 10 + 0.5) * 0.1;
    		cout << avg << " ";
    	}
    
    //A5的输出
    	if (count_A5 == 0)
    	{
    		cout<< 'N';
    	}
    	else
    	{
    		cout<< max_A5;
    	}
    	return 0;
    }
    
  • 相关阅读:
    Centos7永久修改hostname
    centos静态绑定IP地址
    Salesforce 报表开发
    Salesforce 测试类的实践
    Salesforce Aura开发 Component组件开发实践
    Salesforce Aura 开发 Hello World开发实践
    PHP设计模式之工厂模式
    PHP设计模式之单例模式
    PHP截取带有汉字的字符串,将汉字按两个字节计算
    window下安装Apache+PHP
  • 原文地址:https://www.cnblogs.com/zongji/p/12252980.html
Copyright © 2011-2022 走看看