记录编号 347837 评测结果 AAWWWAAAAA
题目名称 排序测试 最终得分 70
用户昵称 GravatarTiny 是否通过 未通过
代码语言 C++ 运行时间 5.648 s
提交时间 2016-11-13 17:18:35 内存使用 70.14 MiB
显示代码纯文本
#include <stdio.h>
#include <stdlib.h>
#include <string>

static const unsigned long long ten_pow[] =
{ 1e0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10,
1e11, 1e12, 1e13, 1e14, 1e15, 1e16, 1e17, 1e18, 1e19 };

class InOut {
	static const size_t MAX_BUF = 35 * 1024 * 1024;
	int read_len, write_len;
	char reader[MAX_BUF], writer[MAX_BUF];

public:
	inline InOut() { read_len = write_len = 0; }

	inline void Begin(const std::string &s) {
		freopen((s + ".in").c_str(), "r", stdin);
		freopen((s + ".out").c_str(), "w", stdout);
		reader[fread(reader, 1, MAX_BUF, stdin)] = '\0';
	}

	inline void End() {
		writer[fwrite(writer + 1, 1, write_len, stdout)] = '\0';
		fclose(stdin); fclose(stdout);
	}

	template <typename T> inline void Read_num(T &num) {
		num = 0; bool minus = false;
		while ((reader[read_len] < '0' || reader[read_len] > '9')
		&& reader[read_len] != '-') ++read_len;
		if (reader[read_len] == '-') { minus = true; ++read_len; }
		while (reader[read_len] >= '0' && reader[read_len] <= '9')
			num = num * 10 + reader[read_len++] - '0';
		if (minus) num = -num;
	}

	template <typename T> inline T Get_num() {
		T num = 0; bool minus = false;
		while ((reader[read_len] < '0' || reader[read_len] > '9')
		&& reader[read_len] != '-') ++read_len;
		if (reader[read_len] == '-') { minus = true; ++read_len; }
		while (reader[read_len] >= '0' && reader[read_len] <= '9')
			num = num * 10 + reader[read_len++] - '0';
		return (minus ? -num : num);
	}

	inline void Read_char(char &ch) { ch = reader[read_len++]; }

	inline char Get_char() { return reader[read_len++]; }

	template <typename T> inline void Write_num(T num) {
		if (num < 0) { num = -num; writer[++write_len] = '-'; }
		int len = 0; for (T _num = num; _num; ++len, _num /= 10);
		while (len) {
			writer[++write_len] = num / ten_pow[--len] + '0';
			num %= ten_pow[len];
		}
	}

	inline void Write_char(const char &ch) { writer[++write_len] = ch; }
} IO;

const size_t MAXN = 2000000 + 10;

int n;
int a[MAXN];

inline int cmp(const void *a, const void *b) { return *(int *)a > *(int *)b; }

int main() {
	IO.Begin("sorttest");
	IO.Read_num(n);
	for (int i = 1; i <= n; ++i) IO.Read_num(a[i]);
	qsort(a + 1, n, sizeof(int), cmp);
	for (int i = 1; i <= n; ++i) { IO.Write_num(a[i]); IO.Write_char(' '); }
	IO.End();
	return 0;
}