-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathUgly_or_Beautiful.cpp
46 lines (43 loc) · 953 Bytes
/
Ugly_or_Beautiful.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
#include <bits/stdc++.h>
using namespace std;
string uglyOrBeautiful(vector <int> a) {
int n = a.size();
int count[n+1];
memset(count, 0, sizeof count);
bool flag = true;
for(int i = 0; i < n; ++i){
if(a[i] < 1 || a[i] > n){
flag = false;
break;
}
if(count[a[i]] > 0){
flag = false;
break;
}
++count[a[i]];
}
bool isAsc = true;
for(int i = 0; i < n-1; ++i){
if(a[i] > a[i+1]){
isAsc = false;
break;
}
}
if(!isAsc && flag) return "Beautiful";
else return "Ugly";
}
int main() {
int q;
cin >> q;
for(int a0 = 0; a0 < q; a0++){
int n;
cin >> n;
vector<int> a(n);
for(int a_i = 0; a_i < n; a_i++){
cin >> a[a_i];
}
string result = uglyOrBeautiful(a);
cout << result << endl;
}
return 0;
}