Go Weight + Sort Board (SET+MAP)

Source: Internet
Author: User
Tags cmath

Test instructions

Given the number of N, the number of outputs to reorder and the number of each

1.MAP implementations

#pragma GCC optimize ("O2") #include <iostream> #include <cstdio> #include <cstring> #include < algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <map > #include <limits.h> #include <ctime> #define N 100001typedef long long ll;const int inf=999999999;const int maxn=2017;using namespace Std;inline int Read () {    int f=1,x=0;char ch=getchar ();    while (ch> ' 9 ' |ch< ' 0 ')    {        if (ch== '-')        f=-1;        Ch=getchar ();    }    while (ch<= ' 9 ' &&ch>= ' 0 ')    {        x= (x<<3) + (x<<1) +ch-' 0 ';        Ch=getchar ();    }    return f*x;} typedef map<int,bool> MP;MP M;int Main () {int n=read (); for (int i=1;i<=n;i++) {int k=read (); m[k]=1;} Cout<<m.size () <<endl;for (Mp::iterator i=m.begin (); I!=m.end (); i++) cout<<i->first<< Endl;}

2.set implementations

#pragma GCC optimize ("O2") #include <iostream> #include <cstdio> #include <cstring> #include < algorithm> #include <cmath> #include <queue> #include <stack> #include <set> #include <map > #include <limits.h> #include <ctime> #define N 100001typedef long long ll;const int inf=999999999;const int maxn=2017;using namespace Std;inline int Read () {    int f=1,x=0;char ch=getchar ();    while (ch> ' 9 ' |ch< ' 0 ')    {        if (ch== '-')        f=-1;        Ch=getchar ();    }    while (ch<= ' 9 ' &&ch>= ' 0 ')    {        x= (x<<3) + (x<<1) +ch-' 0 ';        Ch=getchar ();    }    return f*x;} Set<int>s;int Main () {    int n=read ();    for (int i=1;i<=n;i++)    {int k=read (); S.insert (k);}    printf ("%d", s.size ());    For (Set<int>::iterator I=s.begin (); I!=s.end (); i++)    Cout<<*i<<endl;}

Go Weight + Sort Board (SET+MAP)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.