讨论 / 参考程序
sunxiangqing 2017-11-21 18:45:50
点我顶贴 收藏 删除
var n,i,x,k1,k2:longint;

tong:array[-1000..1000]of longint;

begin

readln(n);

for i:=1 to n do

begin

read(x);

tong[x]:=1;

end;

for i:=-1000 to 1000 do

if tong[i]=1 then

begin

k1:=k1+1;

end;

writeln(k1);

for i:=-1000 to 1000 do

if tong[i]<>0 then

begin

inc(k2);

if k2=1 then write(i) else write(' ',i);

end;

end.

#1 linxinchang16@2017-12-03 10:19:36
回复 删除
#include<iostream>

using namespace std;

int a[101],x,y,z,i,j,k,n,m,b[101],tot;

int paixu(int *a,int n)

{

int zhi,bao;

for(int i=1;i<=n;i++)

{

bao=a[i];

zhi=i-1;

while((zhi>=0)&&(bao<a[zhi]))

{

a[zhi+1]=a[zhi];

zhi--;

}

a[zhi+1]=bao;

}

}

int shanchu(int *a,int n)

{

int zhi;

for(int i=1;i<=n;i++)

{

if(a[i]!=a[i-1])

tot++;

}

}

int main()

{

cin>>n;

for(i=1;i<=n;i++)

cin>>a[i];

paixu(a,n);

shanchu(a,n);

cout<<tot<<endl;

cout<<a[1];

for(i=2;i<=n;i++)

{

if(a[i]!=a[i-1]) cout<<" "<<a[i];

}

}

#2 linxinchang16@2017-12-03 10:20:10
回复 删除
//很慢的

#include<iostream>

using namespace std;

int a[101],x,y,z,i,j,k,n,m,b[101],tot;

int paixu(int *a,int n)

{

int zhi,bao;

for(int i=1;i<=n;i++)

{

bao=a[i];

zhi=i-1;

while((zhi>=0)&&(bao<a[zhi]))

{

a[zhi+1]=a[zhi];

zhi--;

}

a[zhi+1]=bao;

}

}

int shanchu(int *a,int n)

{

int zhi;

for(int i=1;i<=n;i++)

{

if(a[i]!=a[i-1])

tot++;

}

}

int main()

{

cin>>n;

for(i=1;i<=n;i++)

cin>>a[i];

paixu(a,n);

shanchu(a,n);

cout<<tot<<endl;

cout<<a[1];

for(i=2;i<=n;i++)

{

if(a[i]!=a[i-1]) cout<<" "<<a[i];

}

}//很慢的啦

查看更多回复
提交回复