zoukankan      html  css  js  c++  java
  • 【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
    ",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
    ",a[i-1],tot),tot=1;
    		else tot++;
    	return 0;
    }
    

    总之,本题乃签到题也。

    转载需注明出处。
  • 相关阅读:
    Gitlab邮箱配置
    Zabbix邮件告警提示Couldn't resolve host name解决办法
    Gitlab备份和恢复操作
    Gitlab权限管理
    编译安装Nginx
    [0] 数据库读写分离
    [0] C# & MongoDB
    [0] 平衡二叉树
    [0] 分布式存储 Memcached
    [0] MSSQL 分库查询
  • 原文地址:https://www.cnblogs.com/jz929/p/11817811.html
Copyright © 2011-2022 走看看