8 条题解

  • 5
    @ 2022-7-12 8:01:37

    两个黑科技 sort为排序函数,将数组从大到小排序 unique为除重函数,将相邻的重复元素去除;

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int a[101],b,p=0,k=0;
    	while(cin>>b)
    	{
    		a[p++]=b;
    		k++;
    	}
    	sort(a,a+k);
    	k=unique(a,a+k)-a;
    	for(int i=0;i<k;i++)
    	{
    		cout<<a[i]<<" ";
    	}
    	
    }
    
    • 2
      @ 2022-7-14 9:34:32

      没有黑科技

      using namespace std;
      const int A=1000;
      int n[A];
      int main(){
      	int a,sum=0;
      	while(cin>>a){
      		n[sum]=a;
      		sum++;
      	}
      	for(int i=1;i<=10000;i++){
      		for(int r=0;r<=sum-2;r++){
      			if(n[r]>n[r+1]){
      				swap(n[r],n[r+1]);
      			}
      		}
      	}
      	int b=n[0];
      	cout<<n[0]<<" ";
      	for(int k=1;k<=sum-1;k++){
      		if(n[k]!=b){
      			cout<<n[k]<<" ";
      			b=n[k];
      		}
      		else if(n[k]==b){
      			cout<<"";
      		}
      	}
      	return 0;
      }
      
      • 1
        @ 2023-11-10 9:49:20

        python能过,可惜后台过不了

        import numpy as np
        x=list(map(int,input().split()))
        y=list(map(int,input().split()))
        print(np.unique(np.concatenate((x,y))).tolist())
        
        • 1
          @ 2023-8-19 10:16:19
          a=input().split()
          b=input().split()
          for i in range(len(a)):
              a[i]=int(a[i])
          c=[]
          for i in range(len(b)):
              b[i]=int(b[i])
          for i in a:
              if i not in c:
                  c+=[i]
          for i in b:
              if i not in c:
                  c+=[i]
          c.sort()
          for i in c:
              print(i,end=' ')
          
          • 1
            @ 2023-7-19 10:22:41

            c++

            #include <iostream>
            #include<algorithm>
            using namespace std;
            int main()
            {
            	long long a[110],b[110],c[210],n=0,m=0;
            	while (cin>>a[n]){
                    n++;
            	}
            	while (cin>>b[m]){
                    m++;
            	}
            	for(int i=0;i<=n-1;i++){
                    c[i]=a[i];
            	}
            	for(int i=n;i<=m-1;i++){
                    c[i]=b[i-n];
            	}
            	sort (c,c+n+m);
            	for(int i=0;i<=m+n-1;i++){
                    if(c[i]!=c[i-1]){
                    cout<<c[i]<<' ';
                    }
            	}
            }
            
            • 1
              @ 2022-11-23 10:10:29

              可以练习stl中的set容器 set容器自动删去重复并排序

              #include <bits/stdc++.h>
              using namespace std;
              
              set<int> arr;
              
              
              int main()
              {
              	int a;
              	while(cin >> a) arr.insert(a);
              	for(auto x:arr) cout << x << " ";
              	return 0;
              }
              
              • 1
                @ 2022-7-17 19:22:33
                using namespace std;
                int a[100005];
                int k[100005];
                int main(){
                	int l;
                	int m=0;
                	while(cin>>l){
                		m++;
                		a[m]=l;
                	}
                	sort(a+1,a+1+m);
                	for(int i=1;i<=m;i++){
                		if(a[i]==a[i+1])k[a[i]]++;
                	}
                	for(int i=1;i<=m;i++){
                		if(k[a[i]]!=0){
                			cout<<a[i]<<" ";
                			i=i+k[a[i]];
                			continue;
                		}
                		cout<<a[i]<<" ";
                	}
                	return 0;
                }
                

                吃瓜

                • 0
                  @ 2024-9-7 12:32:02
                  b=input().split()
                  s=[0]*10000
                  for i in a:
                      s[int(i)]=1
                  for i in b:
                      s[int(i)]=1
                  for i in range(0,10000):
                      if s[i]==1:
                          print(i,end=' ')
                  

                  最正经无科技的桶计数,多多关注喵

                  • 1

                  信息

                  ID
                  87
                  时间
                  1000ms
                  内存
                  128MiB
                  难度
                  6
                  标签
                  递交数
                  1180
                  已通过
                  320
                  上传者