8 条题解

  • 0
    @ 2025-7-23 11:08:52
    #include<bits/stdc++.h>
    using namespace std;
    int n,s,m,a[1100],b[1100];
    int main()
    {
    	cin>>n;
    	for(int i=1;i<=n;i++)cin>>a[i];
    	sort(a+1,a+1+n);
    	a[n+1]=-1;
    	s=1;
    	for(int i=2;i<=n+1;i++)
    	{
    		if(a[i]==a[i-1])s++;
    		else{
    			b[a[i-1]]=s;
    			m+=s-1;
    			s=1;
    		}
    	}
    	cout<<n-m<<endl;
    	for(int i=1;i<=1000;i++)if(b[i]>=1)cout<<i<<" "; 
    }
    
    • 0
      @ 2024-2-8 12:20:55

      #include<bits/stdc++.h> using namespace std; bool f[1010]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m=0; cin>>n; for(int i=1;i<=n;i++) { int x; cin>>x; if(!f[x])m++,f[x]=1; } cout<<m<<endl; for(int i=0;i<=1000;i++) if(f[i])cout<<i<<' '; return 0; }

      • 0
        @ 2024-2-8 12:20:32

        #include<bits/stdc++.h> using namespace std; bool f[1010]; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,m=0; cin>>n; for(int i=1;i<=n;i++) { int x; cin>>x; if(!f[x])m++,f[x]=1; } cout<<m<<endl; for(int i=0;i<=1000;i++) if(f[i])cout<<i<<' '; return 0; }

        • 0
          @ 2023-11-14 17:02:14
          #include<bits/stdc++.h>
          using namespace std;
          bool f[1010];
          int main()
          {
          	ios::sync_with_stdio(0);
          	cin.tie(0);
          	cout.tie(0);
          	int n,m=0;
          	cin>>n;
          	for(int i=1;i<=n;i++)
          	{
          		int x;
          		cin>>x;
          		if(!f[x])m++,f[x]=1;
          	}
          	cout<<m<<endl;
          	for(int i=0;i<=1000;i++)
          		if(f[i])cout<<i<<' ';
          	return 0;
          }
          
          
          • 0
            @ 2023-10-12 21:12:55

            明明想在学校中请一些同学一起做一项问卷调查,为了实验的客观性,他先用计算机生成了N个1到1000之间的随机整数(N≤100),对于其中重复的数字,只保留一个,把其余相同的数去掉,不同的数对应着不同的学生的学号。然后再把这些数从小到大排序,按照排好的顺序去找同学做调查。请你协助明明完成“去重”与“排序”的工作。

            输入文件:

            输入文件sx0802.in 有2行,第1行为1个正整数,表示所生成的随机数的个数N;第2行有N个用空格隔开的正整数,为所产生的随机数。

            输出文件:

            输出文件sx0802.out 也是2行,第1行为1个正整数M,表示不相同的随机数的个数。第2行为M个用空格隔开的正整数,为从小到大排好序的不相同的随机数。

            样例:

            输入:

            • 0
              @ 2023-10-11 20:08:00
              #include <bits/stdc++.h>
              using namespace std;
              int i,a[1100],n,x,k;
              int main()
              {
              	cin>>n;
              	for(i=1;i<=n;i++)
              	{
              		cin>>x;
              		a[x]=1;
              	}
              	for(i=1;i<=1000;i++)
              	if(a[i]!=0)k++;
              	cout<<k<<endl;
              	for(i=1;i<=1000;i++)
              	  if(a[i]==1)cout<<i<<" ";
              	return 0;
              }
              
              • 0
                @ 2023-8-7 14:14:29
                #include<bits/stdc++.h>
                using namespace std;
                bool f[1010];
                int main()
                {
                	ios::sync_with_stdio(0);
                	cin.tie(0);
                	cout.tie(0);
                	int n,m=0;
                	cin>>n;
                	for(int i=1;i<=n;i++)
                	{
                		int x;
                		cin>>x;
                		if(!f[x])m++,f[x]=1;
                	}
                	cout<<m<<endl;
                	for(int i=0;i<=1000;i++)
                		if(f[i])cout<<i<<' ';
                	return 0;
                }
                
                • 0
                  @ 2023-7-25 13:10:44
                  #include <bits/stdc++.h>
                  using namespace std;
                  long long a[3000],g,x,n;
                  int main()
                  {
                  	cin>>n;
                  	for(int i=1;i<=n;i++)
                  	{
                  		cin>>x;
                  		a[x]=1;
                  	}
                  	for(int i=1;i<=1000;i++)
                  		g=g+a[i];
                  	cout<<g<<endl;
                  	for(int i=1;i<=1000;i++)
                  		if(a[i]==1) cout<<i<<" "; 
                  	return 0;
                  }
                  
                  • 1

                  信息

                  ID
                  308
                  时间
                  1000ms
                  内存
                  256MiB
                  难度
                  1
                  标签
                  (无)
                  递交数
                  70
                  已通过
                  53
                  上传者