问卷调查

黑曼巴  •  9个月前


include<bits/stdc++.h>

using namespace std; int a[120]; int main() {

int k;
bool ok=true;
cin>>k;
for(int i=1;i<=k;i++)    
  cin>>a[i];
for(int i=0;i<k;i++)
{
	ok=true;
	for(int j=0;j<k-i;j++) 
    {
	    if(a[j]>a[j+1]) 
	    {
	  	    swap(a[j],a[j+1]);
	  	    ok=false;
	    }
    }
    if(ok==true)
      break;
}
for(int i=1;i<k;i++)  //去重 
  if(a[i]==a[i+1]) 
  {
  	  for(int j=i;j<k;j++)
  	    a[j]=a[j+1];
  	  k--;
  	  i--;
  }
cout<<k<<endl;               
for(int i=1;i<=k;i++)
  cout<<a[i]<<" ";
return 0;

}


评论: