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;
    }
    

    总之,本题乃签到题也。

    转载需注明出处。
  • 相关阅读:
    ssm依赖
    NSNotificationCenter详解
    Objective-C语法之代码块(block)的使用
    IOS UI UITableView
    IOS 多线程(4) --线程通讯
    IOS 多线程(3) --线程安全
    IOS 多线程(2) --NSThread
    IOS 多线程(1) --基础知识
    IOS UI TextFiled常用总结
    IOS UI TabBar标签栏的使用
  • 原文地址:https://www.cnblogs.com/jz929/p/11817811.html
Copyright © 2011-2022 走看看