1. 程式人生 > >【提高組NOIP2007】統計數字

【提高組NOIP2007】統計數字

本題排序輸出即可。

#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[200010],tot=1;

inline int read()
{
	int x=0; char c=getchar();
	while (c<'0' || c>'9') c=getchar();
	while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x;
}

void
qsort(int l,int r) { int i=l,j=r,mid=a[l+r>>1]; while (i<j) { while (a[i]<mid) i++; while (a[j]>mid) j--; if (i<=j) swap(a[i++],a[j--]); } if (i<r) qsort(i,r); if (l<j) qsort(l,j); } int main() { freopen("count.in","r",stdin); freopen("count.out","w",stdout); n=
read(); for (int i=1;i<=n;i++) a[i]=read(); qsort(1,n);a[++n]=-1; for (int i=2;i<=n;i++) if (a[i]!=a[i-1]) printf("%d %d\n",a[i-1],tot),tot=1; else tot++; return 0; }

本來想打成這樣的:(可惜XC不給。。。)

#include<cstdio>
#include<algorithm>
using namespace std;
int n,a[200010],tot=1;

inline int
read() { int x=0; char c=getchar(); while (c<'0' || c>'9') c=getchar(); while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar(); return x; } int main() { freopen("count.in","r",stdin); freopen("count.out","w",stdout); n=read(); for (int i=1;i<=n;i++) a[i]=read(); sort(a+1,a+n+1);a[++n]=-1; for (int i=2;i<=n;i++) if (a[i]!=a[i-1]) printf("%d %d\n",a[i-1],tot),tot=1; else tot++; return 0; }

總之,本題乃簽到題也。