-
Notifications
You must be signed in to change notification settings - Fork 4
/
BCNEPER.cpp
71 lines (70 loc) · 1.04 KB
/
BCNEPER.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
void khoitao(int a[], string num,int n){
for (int i=0;i<num.length();i++){
a[i+1]=(num[i]-'0');
}
}
void xuat(int a[],int n,int dem){
cout<<dem<<" ";
for (int i=1;i<=n;i++){
cout<<a[i];
}
cout<<endl;
}
bool check(int a[],int n){
for (int i=1;i<n;i++){
if (a[i]<a[i+1]) return false;
}
return true;
}
// 1 2 3 4
// 1 2 4 3
// 1 3 2 4
// 1 3 4 2
// 1 4 2 3
// 1 4 3 2
void sinhlk(int a[],int n,int dem){
if (check(a,n)==true) cout<<dem<<" "<<"BIGGEST"<<endl;
while (check(a,n)==false){
int i;
for (i=n;i>0;i--){
if (a[i]>a[i-1]) break;
}
i--;
for (int j=n;j>=i;j--){
if (a[j]>a[i]){
swap(a[i],a[j]);
sort(a+i+1,a+1+n);
xuat(a,n,dem);
break;
}
}
break;
}
}
int main(){
int T;
cin>>T;
while(T--){
int dem;
string num;
int a[90];
cin>>dem>>num;
int n=num.length();
khoitao(a,num,n);
sinhlk(a,n,dem);
}
return 0;
}