P1029-P1030
#include<iostream>
#include<algorithm>
using
namespace
std;
int
main()
{
int
n;
cin>>n;
int
a[101];
int
b[101];
int
rest=0;
int
i;
a[0]={0};
for
(
int
i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
for
(
int
i=0;i<n;i++)
{
if
(i>0&&a[i]!=a[i-1]||i==0)//不能忽略i=0
{
b[rest]=a[i];
rest++;
}
}
cout<<rest<<endl;
for
(
int
i=0;i<rest-1;i++)
{
cout<<b[i]<<
" "
;
}
cout<<b[rest-1];
return
0;
}
//一个冒泡排序
#include<iostream>
#include<algorithm>
using
namespace
std;
int
main()
{
int
n;
cin>>n;
int
train[1001];
int
change=0;
for
(
int
i=1;i<=n;i++)
{
cin>>train[i];
}
for
(
int
i=n-1;i>=0;i--)
{
for
(
int
j=1;j<=i;j++)
if
(train[j]>train[j+1])
{
swap(train[j],train[j+1]);
change++;
}
}
cout<<change<<endl;
return
0;
}