#include <iostream>
#include <algorithm>
using namespace std;
int cmp(int a , int b){
return a>b;
}
int ssjj(int c , int d){
return d>c;
}
int main()
{
int a,b[100],c;
while (cin>>a){
for (int i=0;i<a;i++){
cin>>b[i];
}
sort ( b , b+a , ssjj );
for (int i=0;i<a;i++){
cout<<b[i]<<" ";
}
cout<<'\n';
sort ( b , b+a , cmp );
for (int i=0;i<a;i++){
while (b[i]==b[i+1]){
i++;
}
cout<<b[i]<<" ";
}
cout<<endl;
}
}
#include
#include
using namespace std;
int cmp(int a , int b){
return a>b;
}
int ssjj(int c , int d){
return d>c;
}
int main()
{
int a,b[100],c;
while (cin>>a){
for (int i=0;i<a;i++){
cin>>b[i];
}
sort ( b , b+a , ssjj );
for (int i=0;i<a;i++){
cout<<b[i]<<" ";
}
cout<<'\n';
sort ( b , b+a , cmp );
for (int i=0;i<a;i++){
while (b[i]==b[i+1]){
i++;
}
cout<<b[i]<<" ";
}
cout<<endl;
}
}
reverse
內建在algorithm這個標頭檔
功能也是降冪排列
#include
#include
using namespace std;
int cmp(int a , int b){
return a>b;
}
int ssjj(int c , int d){
return d>c;
}
int main()
{
int a,b[100],c;
while (cin>>a){
for (int i=0;i<a;i++){
cin>>b[i];
}
sort ( b , b+a , ssjj );
for (int i=0;i<a;i++){
cout<<b[i]<<" ";
}
cout<<'\n';
sort ( b , b+a , cmp );
for (int i=0;i<a;i++){
while (b[i]==b[i+1]){
i++;
}
cout<<b[i]<<" ";
}
cout<<endl;
}
}
reverse
內建在algorithm這個標頭檔
功能也是降冪排列
可以試試看先大到小排列
把大到小排列改成reverse(b,b+a)
然後再找重複的
最後再輸出
加油!