PAT乙题1012. 数字分类 (20)

2018/01/25 PAT 共 1127 字,约 4 分钟
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<map>
#include<string>
#include<fstream>
#include<vector>
#include<stack>
#include<functional>
using namespace std;

int main() {
#ifdef LOCAL
	freopen("d:\\datain.txt", "r", stdin);
	freopen("d:\\dataout.txt", "w", stdout);
#endif LOCAL
	int n,d;
	double a4 = 0.0;
	int a1 = 0, a2 = 0, a3 = 0, a5 = 0, t1, t2;
	t1 = 0;
	t2 = 0;
	bool f2= false;
	int t3 = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> d;
		if (d % 10 == 0) {
			a1 += d;
		}
		else if (d % 5 == 1) {
			//cout << (int)pow(-1,t1)*d << "!!" << endl;
			a2 += ((int)pow(-1, t1)*d);
			t1++;
			f2 = true;
		}
		else if (d % 5 == 2) {
			a3++;
		}
		else if (d % 5 == 3) {
			t2 += d;
			t3++;
		}
		else if (d % 5 == 4&&d>a5) {
			a5 = d;
		}


	}
	//cout << t2 << "!" << t3 << endl;
	if (a1 > 0)
		cout << a1 << " ";
	else
		cout << "N ";
	if (f2 == true) {
		cout << a2 << " ";
	}
	else
		cout << "N ";
	if (a3 > 0)
		cout << a3 << " ";
	else
		cout << "N ";
	if (t2>0)
		printf("%.1f ", (double)t2/t3);
	else
		cout << "N ";
	if (a5 > 0)
		cout << a5;
	else
		cout << "N";
	return 0;
}

Search

    Table of Contents