首页 > 代码库 > [luoguP1097] 统计数字(水)

[luoguP1097] 统计数字(水)

传送门

 

这么水的题,也只有提高组第一题了吧

 

代码

#include <cstdio>#include <iostream>#include <algorithm>#define N 200001int n, cnt = 1;int a[N];inline int read(){	int x = 0, f = 1;	char ch = getchar();	for(; !isdigit(ch); ch = getchar()) if(ch == ‘-‘) f = -1;	for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - ‘0‘;	return x * f;}int main(){	int i;	n = read();	for(i = 1; i <= n; i++) a[i] = read();	std::sort(a + 1, a + n + 1);	for(i = 1; i <= n; i++)	{		if(a[i] ^ a[i + 1])		{			printf("%d %d\n", a[i], cnt);			cnt = 1;		}		else cnt++;	}	return 0;}

  

[luoguP1097] 统计数字(水)