372 条题解

  • -1
    @ 2018-03-08 14:00:38

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int a[4223];
    int main()
    {
    int num=0,n;
    cin>>n;
    for (int i=0;i<n;i++)
    {
    cin>>a[i];
    }
    sort(a,a+n);
    for (int i=0;i<n;i++)
    {
    if (a[i]!=a[i+1]) num+=1;;
    }
    cout<<num<<endl;
    for (int i=0;i<n;i++)
    {
    if (a[i]!=a[i+1]) cout<<a[i]<<" ";
    }

    return 0;
    }

  • -1
    @ 2018-03-07 21:55:50
    #include<iostream>
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        int *a = new int[n];
        for (int i = 0; i < n; i++)
            cin >> a[i];
        int temp;
        for (int i = 1; i < n; i++)
        {
            for (int j = 0; j < n - i; j++)
            {
                if (a[j] > a[j + 1])
                {
                    temp=a[j];
                    a[j] = a[j + 1];
                    a[j + 1] = temp;
                }
            }
        }
        int cnt = n;
        for (int i = 0; i < n-1; i++)
        {
            if (a[i] == a[i + 1])
                cnt--;
        }
        cout << cnt << endl;
        for (int i = 0; i < n - 1; i++)
        {
            if (a[i] != a[i + 1])
                cout << a[i] << " ";
        }
        cout << a[n - 1];
        delete[]a;
        return 0;
    }
    
  • -1
    @ 2018-02-18 16:16:52

    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    #include <set>
    using namespace std;
    set<int> arr;
    int main()
    {
    int n;
    cin >> n;
    int x;
    for (int i = 0; i < n; i++)
    {
    cin >> x;
    arr.insert(x);
    }
    cout << arr.size() << endl;
    for (auto x = arr.begin(); x != arr.end(); x++)
    cout << *x << " ";
    cout << endl;
    return 0;
    }

  • -1
    @ 2018-02-03 10:57:46

    #include <bits/stdc++.h>
    using namespace std;
    char b[1010];
    int main(){
    int n,i,x,s=0;
    cin>>n;
    for(i=1;i<=n;i++){
    cin>>x;
    b[x]++;
    }
    for(i=1;i<=1000;i++)
    if(b[i]!=0)
    s++;
    cout<<s<<endl;
    for(i=1;i<=1000;i++)
    if(b[i]!=0)
    cout<<i<<" ";
    return 0;
    }

  • -1
    @ 2017-12-19 12:12:05

    var
    i,j,n,s,b:longint;
    a:array[1..1000]of integer;
    begin
    readln(n);
    for i:=1 to n do
    begin
    read(b);
    a[b]:=a[b]+1;
    if a[b]=1 then s:=s+1;
    end;
    writeln(s);
    for i:=1 to 1000 do
    if a[i]>0 then write(i,' ');
    end.

  • -1
    @ 2017-11-24 10:14:48

    用桶排序比较适合

  • -1
    @ 2017-11-23 13:51:55

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    int s,n;
    cin>>n;
    int a[n];
    for(s=0;s<n;s++)
    cin>>a[s];
    sort(a,a+n);
    int m=unique(a,a+n)-a;
    cout<<m<<endl;
    for(s=0;s<m;s++)
    cout<<a[s]<<" ";
    }

  • -1
    @ 2017-11-23 13:49:45
    int n,arr[101]={0},t[101]={0};
    int _read(){
        int x=0;
        char c=getchar();
        while(c<'0'||c>'9') c=getchar();
        while(c>='0' && c<='9') x=x*10+c-'0', c=getchar();
        return x;
    }
    void merge_sort(int *a, int l, int r , int *t) {
        if(r-l>1) {
            int m=(l+r)>>1;
            int p=l, q=m, i= l;
            merge_sort(a,l,m,t);
            merge_sort(a,m,r,t);
            while(p<m || q<r){
                if(q>=r || (p<m && a[p]<a[q])) t[i++] = a[p++];
                else t[i++] = a[q++];
            }
            for(i=l; i<r; i++)  a[i]= t[i];
        }
    }
    int main() {
        n=_read();
        int c=1,tx;
        for(int i=1; i<=n; i++){
        arr[i]=_read();
        }
        merge_sort(arr,1,n+1,t);
    for(int i=1;i<n;i++){
            if(arr[i]==arr[i+1]) continue;
            c++;
        }
        printf("%d\n",c);
        for(int i=1;i<n;i++){
            if(arr[i]==arr[i+1]) continue;
            printf("%d ",arr[i]);
        }
        printf("%d", arr[n]);
        return 0;
    }
    
  • -1
    @ 2017-11-11 11:45:16

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int a[101];
    int main()
    {
    int n,i,c;
    c=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
    cin>>a[i];
    }
    sort(a,a+n);
    a[n]=0;
    for(i=0;i<n;i++)
    {
    if(a[i]!=a[i+1])
    {
    c++;
    }
    }
    cout<<c<<endl;
    for(i=0;i<n;i++)
    {
    if(a[i]!=a[i+1])
    {
    cout<<a[i]<<" ";
    }
    }
    cout<<endl;
    system ("pause");
    return 0;
    }

  • -1
    @ 2017-10-04 13:01:37

    轻松桶排序。
    #include <iostream>
    using namespace std;

    int n,temp;
    int arr[1005];

    int main() {
    cin>>n;
    for(int i=1;i<=n;i++){
    cin>>temp;
    arr[temp]++;
    }
    int number=0;
    for(int i=1;i<=1000;i++){
    if(arr[i]!=0){
    number++;
    }
    }
    cout<<number<<endl;
    for(int i=1;i<=1000;i++){
    if(arr[i]!=0){
    cout<<i<<' ';
    }
    }
    return 0;
    }

  • -1
    @ 2017-10-03 10:46:19

    #include<iostream>
    #include<set>
    #include<algorithm>
    #define MAX_N 105
    using namespace std;
    int N;
    int num[MAX_N];
    set<int>used;
    void read(){
    cin>>N;
    for (int i=1;i<=N;i++){
    cin>>num[i];
    used.insert(num[i]);
    }
    }
    void solve();
    int main(){
    read();
    solve();
    return 0;
    }
    void solve(){
    set<int>::iterator i;
    cout<<used.size()<<endl;
    for (i=used.begin();i!=used.end();i++){
    cout<<*i<<" ";
    }
    }

  • -1
    @ 2017-09-24 07:47:33

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int main()
    {
    int N,sum=0;
    int a[120];
    cin>>N;
    for(int i=0;i<N;i++)
    {
    cin>>a[i];
    }
    sort(a,a+N);
    for(int i=0;i<N;i++)
    {
    for(int j=i+1;j<N;j++)
    {
    if(a[i]==a[j])
    a[j]=0;
    }
    }
    for(int i=0;i<N;i++)
    {
    if(a[i]!=0)
    sum++;
    }
    cout<<sum<<endl;
    for(int i=0;i<N;i++)
    {
    if(a[i]!=0)
    cout<<a[i]<<" ";
    }
    return 0;
    }

  • -1
    @ 2017-09-22 19:39:22

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int a[101],b[101];
    int main()
    {
    int n,sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
    cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
    for(int j=i;j<n;j++)
    if(a[i]==a[j]&&i!=j)
    {
    b[j]=1;
    }
    }
    for(int i=0;i<n;i++)
    {
    if(b[i]==0)
    {
    sum++;
    }

    }
    cout<<sum<<endl;
    for(int i=0;i<n;i++)
    {
    if(b[i]==0)
    {
    cout<<a[i]<<" ";
    }
    }
    return 0;
    }

  • -1
    @ 2017-09-18 10:36:27

    。。。。直接函数去重,,,

    #include<cstdio>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    
    int a[105],n;;
    
    int main(){
        cin>>n;
        for(int i=0;i<n;i++) scanf("%d",&a[i]);
        sort(a,a+n);
        int len=unique(a,a+n)-a;
        cout<<len<<endl;
        for(int i=0;i<len;i++) printf("%d ",a[i]);
        return 0;
    }
    
    
  • -1
    @ 2017-08-29 10:33:37

    #include<iostream>
    #include<algorithm>
    int main()
    {
    using namespace std;
    int a[200],b[1001]={0},n,x,m=0;
    cin>>n;
    for (int i=0;i<n;i++)
    {
    cin>>x;
    if (b[x]!=1) a[m]=x,b[x]=1,m++;
    }
    sort(a,a+m);
    cout<<m<<endl;
    for (int i=0;i<m;i++)
    {
    cout<<a[i];
    if (i!=m-1) cout<<" ";
    }
    }
    c++初学者

  • -1
    @ 2017-08-24 20:11:49

    Ey3JeU LV 4 @ 36秒前

    #include<iostream>
    #include<cstring>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    int main()
    {
    int n,k;
    int s=0;
    int a[101]={0};
    int b[1001]={0};**//根据数据大小设置判断数组,赋初值为0**
    cin>>n;
    for (int i=1;i<=n;i++)
    {
    cin>>k;//逐一读入数据
    if (b[k]==0) //判断读入数据是否重复
    a[i]=k,b[k]=1;//更新判断数组
    else
    s+=1;//记录重复次数
    }
    sort(a+1,a+n+1);//快排
    cout<<n-s<<endl;
    for (int i=1;i<=n;i++)
    if (a[i]!=0)
    cout<<a[i]<<" ";
    }

  • -1
    @ 2017-08-21 11:09:20
    n=int(input())
    a=list(set(list(map(int,input().split()))))
    a.sort()
    print(len(a))
    for i in range(len(a)-1):
        print(str(a[i])+' ',end='')
    print(a[len(a)-1],end='')
    
  • -1
    @ 2017-08-15 01:53:07
    #include <iostream>
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    int main() {
        int a[10000],n,i,g,r;
        scanf("%d",&n);
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
        }
        sort(a+1,a+n+1);
        r=n;
        for(i=1;i<=n;i++)
        {
            if(a[i]!=g)
            {
                g=a[i];
                
            }
            else
            r--;
        }
        printf("%d\n",r); 
        for(i=1;i<=n;i++)
        {
            if(a[i]!=g)
            {
                printf("%d ",a[i]);
                g=a[i];
            }
        }
        return 0;
    }
    
  • -1
    @ 2017-08-10 22:07:26

    var n,sum,max,i:integer; a:array[0..101] of integer;
    b:array[0..10001] of byte;
    begin
    readln(n);
    sum:=0;
    for i:=1 to n do
    begin
    read(a[i]);
    if (sum<a[i]) then sum:=a[i];
    if (b[a[i]]=0) then
    begin
    inc(max);
    b[a[i]]:=1;
    end;
    end;
    writeln(max);
    for i:=1 to sum do
    if (b[i]=1) then write(i,' ');
    writeln;
    end.

  • -1
    @ 2017-07-29 20:48:03
    #include <set>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int main ()
    {
        set<int> s;
        int n,x;
        cin>>n;
        for(int i=0;i<n;i++)
        {
            cin>>x;
            s.insert(x);
        }
        cout<<s.size()<<endl;
        for(set<int>::iterator it=s.begin();it!=s.end();it++)
            cout<<*it<<" "; 
        return 0;
    }
    

信息

ID
1316
难度
3
分类
其他 | 排序 点击显示
标签
递交数
9961
已通过
4874
通过率
49%
被复制
33
上传者