1 solutions

  • 0
    @ 2024-11-27 2:12:27

    1.set

    #include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
    	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    	
    	set<int> st;
        int n;cin>>n;
        for(int i=1;i<=n;++i)
        {
            int x;cin>>x;
            st.insert(x);
        }
        cout<<st.size()<<'\n';
        for(auto &i:st)cout<<i<<' ';
    	return 0;
    }
    
    

    2.vector

    #include<bits/stdc++.h>
    using namespace std;
    
    vector<int> v;
    int main()
    {
    	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    	
    	int n;cin>>n;
    	for(int i=1;i<=n;++i)
    	{
    		int x;cin>>x;
    		v.push_back(x);
    	}
    	sort(v.begin(),v.end());
    	v.erase(unique(v.begin(),v.end()),v.end());
    	cout<<v.size()<<'\n';
    	for(auto &i:v)cout<<i<<' ';
    	
    	return 0;
    }
    
    

    Information

    ID
    4777
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    10
    Tags
    # Submissions
    5
    Accepted
    3
    Uploaded By