Cut the sticks

Cut the sticks

AC代码:(一个数组存数字种类另一个存这个种类的数字的个数)

#include <iostream>
#include <bits/stdc++.h>
using namespace std;


int main()
{
    int i, n, a[1000+10], b[1000+10], x, h;
    while(scanf("%d",&n)!=EOF)
    {
        int q = n;
        memset(a, 0, sizeof(a));
        memset(b, 0, sizeof(b));
        h = 0;
        for(i = 0; i<n; i++)
        {
            cin>>x;
            if(b[x]==0)
                a[h++] = x;
            b[x]++;
        }
        sort(a, a+h);
        printf("%d\n",n);
        for(i = 0; i<h-1; i++)
        {
            printf("%d\n",q-b[a[i]]);
            q = q-b[a[i]];
        }
    }
    return 0;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-03
  • 2022-02-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-18
  • 2021-11-16
  • 2021-08-12
  • 2021-11-24
  • 2021-12-01
  • 2022-12-23
相关资源
相似解决方案