345 条题解

  • 6
    @ 2017-12-02 15:15:09

    #include <iostream>
    #include <cstring>
    using namespace std;
    int main()
    {
    int n,a[1009]={0},t,s=0;
    cin>>n;
    for (int i=1;i<=n;++i)
    {
    cin>>t;
    a[t]++;
    }
    for (int i=1;i<=1000;++i)
    {
    if (a[i]!=0)
    {
    ++s;
    }
    }
    cout<<s<<endl;
    for (int i=1;i<=1000;++i)
    {
    if (a[i]!=0)
    {
    cout<<i<<" ";
    }
    }
    cout<<endl;
    return 0;
    }

  • 4
    @ 2017-10-09 17:38:05

    #include <iostream>
    #include <algorithm>
    using namespace std;
    int a[1010];
    int book[1010];
    int main()
    {
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<n;i++)
    {
    ans++;
    book[i]=1;
    if(i)
    {
    if(a[i]==a[i-1])
    {
    ans--;
    book[i]=0;
    }
    }
    }
    cout<<ans<<endl;
    for(int i=0;i<n;i++)
    {
    if(i)
    cout<<" ";
    if(book[i])
    cout<<a[i];
    }
    cout<<endl;
    return 0;
    }
    输出格式有问题竟然能AC...

    • @ 2017-10-10 18:12:09

      有重复元素的时候会多输出空格……
      呃……可能数据水吧,本来就是个水题不是

    • @ 2019-07-25 11:35:48

      @
      054545641
      : sort是个好东西

  • 1
    @ 2019-07-21 14:42:39

    不是直接用set就过了吗哈哈哈

    #include <iostream>
    #include <algorithm>
    #include <cstring>
    #include <set>
    using namespace std;
    
    set<int> store;
    
    int main()
    {
        int n, temp;
        cin >> n;
        for(int i=0; i<n; i++){
            cin >> temp;
            store.insert(temp);
        }
    
        cout << store.size() << endl;
        set<int>::iterator it;
        for(it = store.begin(); it!=store.end(); it++){
            cout << *it << " ";
        }
    
        return 0;
    }
    
  • 1
    @ 2019-05-26 23:43:47
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    int n,a[120],i,k,x,j;
    bool f[1100];
    int comp(int a,int b)
    {
        if(a<b) return 1;
        else return 0;
    }
    int main()
    {
        memset(f,0,sizeof(f));
        scanf("%d",&n);
        j=0;
        for(i=1;i<=n;i++)
        {
            scanf("%d",&x);
            if(f[x]==1) continue;
            if(f[x]==0) { j++; a[j]=x; f[x]=1; k++; }
        }
        sort(a+1,a+k+1,comp);
        cout<<k<<endl;
        for(i=1;i<=k;i++) cout<<a[i]<<' ';
        return 0;
    }
    
  • 1
    @ 2019-01-04 22:38:23

    b=eval(input())
    ass=list(map(int,input().split()))
    asss=list(set(ass))
    asss.sort()
    print(len(asss))
    for a in asss:
    print(a,end=' ')

  • 1
    @ 2018-09-18 15:08:40

    #include<bits/stdc++.h>
    using namespace std;
    bool a[1008]={false};
    int main()
    {
    int n,b[1008],ans=0,c[1008]={0},temp=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
    scanf("%d",&b[i]);
    a[b[i]]={true};
    }
    for(int i=1;i<=1000;i++)
    {
    if(a[i])
    ans++;
    }
    sort(b,b+n+1);
    printf("%d\n",ans);
    printf("%d",b[1]," ");
    temp=b[1];
    for(int i=2;i<=n;i++)
    {
    if(b[i]!=temp)
    {
    cout<<" "<<b[i];
    temp=b[i];
    }
    else
    continue;
    }
    return 0;
    }

  • 1
    @ 2018-09-09 17:11:20

    #include<bits/stdc++.h>
    using namespace std;
    int a[1002];

    int main()
    {
    memset(a,0,sizeof(a));
    int m=0,n;
    cin>>n;
    int b[n];
    for(int i=0;i<n;i++)
    cin>>b[i];
    for(int i=0;i<n;i++)
    a[b[i]]=1;
    for(int i=0;i<1001;i++)
    if(a[i]==1)
    m++;
    cout<<m<<endl;
    for(int i=0;i<1001;i++)
    if(a[i]==1)
    cout<<i<<" ";
    return 0;
    }

  • 1
    @ 2018-08-18 14:28:44

    直接sort+判重即可,水过

    #include<iostream>
    #include<algorithm>
    using namespace std;
    int a[101];
    int main()
    {
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        sort(a+1,a+n+1);
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            if(a[i]!=a[i-1])
                ans++;
        }
        cout<<ans<<endl;
        for(int i=1;i<=n;i++)
        {
            if(a[i]!=a[i-1])
                cout<<a[i]<<' ';
        }
        return 0;
    }
    
    
  • 1
    @ 2018-08-08 14:03:56

    Pascal党们,我又来了
    var
    a:array[1..1000] of longint;
    n,i,x,t:longint;
    begin
    fillchar(a,sizeof(a),0);
    read(n);
    t:=0;
    for i:=1 to n do
    begin
    read(x);
    inc(a[x]);
    end;;
    for i:=1 to 1000 do
    if a[i]<>0 then inc(t);
    writeln(t);
    for i:=1 to 1000 do
    if a[i]<>0 then write(i,' ');
    end.
    记住,我就是国服亚索

  • 1
    @ 2018-06-28 21:27:20

    桶排序即可,超简单

    #include<iostream>
    using namespace std;
    int main()
    {
        int n,tmp,a[1001]={0},tot=0;
        cin>>n;
        for (int i=1;i<=n;i++)
        {
            cin>>tmp;
            a[tmp]=1;
        }
        for (int i=1;i<=1000;i++)
            if (a[i]==1)
                tot++;
        cout<<tot<<endl;
        for (int i=1;i<=1000;i++)
            if (a[i]==1)
                cout<<i<<' ';
        return 0;
    }
    
  • 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-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-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<<" ";
    }
    }

  • 0
    @ 2019-07-30 07:10:53

    简单如我:
    #include<iostream>
    #include<algorithm>
    using namespace std;

    int res[100];
    int main(){
    int n,tmp;
    cin>>n;

    int M=0;
    for(int i=0;i<n;i++){
    cin>>tmp;
    if(find(res,res+M,tmp)==res+M)
    res[M++]=tmp;
    }
    sort(res,res+M);

    cout<<M<<endl;
    for(int j=0;j<M;j++)
    cout<<res[j]<<' ';
    cout<<endl;
    return 0;
    }

  • 0
    @ 2019-06-18 08:40:38

    #include <iostream>
    using namespace std;
    int main(void)
    {
    int n, a[100] = { 0 };
    int b[100] = { 0 };
    int j = 0, t = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
    cin >> a[i - j];
    for (int k = 0; k < i-j; ++k) {
    if (a[i-j] == a[k]) {
    a[i - j] = 0;
    ++j;
    break;
    }
    }
    }
    cout << n - j << endl;
    for (int k = 0; k < n - j; ++k) {
    for (int i = 0; i < n-j; ++i) {
    if (a[t] > a[i])t = i;
    }
    b[k] = a[t];
    a[t] = 2147483647;
    }
    for (int i = 0; i < n - j; ++i)cout << b[i] << ' ';
    return 0;
    }

信息

ID
1316
难度
3
分类
其他 | 排序 点击显示
标签
递交数
9421
已通过
4560
通过率
48%
上传者