-
Notifications
You must be signed in to change notification settings - Fork 0
/
BasicProgramming1.cpp
66 lines (62 loc) · 1.53 KB
/
BasicProgramming1.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll case1345(ll t, ll* A, ll n) {
if(t == 1) return 7;
else if(t == 3) {
ll min = A[0], max = A[0];
for(ll i = 1; i < 3; i++) {
if(min > A[i]) min = A[i];
if(max < A[i]) max = A[i];
}
return A[0] + A[1] + A[2] - min - max;
}
else if(t == 4) {
ll sum = 0;
for(ll i = 0; i < n; i++)
sum += A[i];
return sum;
}
else {
ll sum = 0;
for(ll i = 0; i < n; i++)
if(A[i] % 2 == 0) sum += A[i];
return sum;
}
}
string case267(ll t, ll* A, ll n) {
if(t == 2) {
if(A[0] > A[1]) return "Bigger";
else if(A[0] == A[1]) return "Equal";
else return "Smaller";
}
else if(t == 6) {
string ans = "";
for(ll i = 0; i < n; i++) {
A[i] %= 26;
ans += (A[i] + 'a');
}
return ans;
}
else {
ll currentIndex = 0;
ll step = 0;
while(0 <= currentIndex and currentIndex <= n-1) {
if(currentIndex == n-1) return "Done";
currentIndex = A[currentIndex];
step++;
if(step > n) return "Cyclic";
}
return "Out";
}
}
int main() {
ll n, t;
cin >> n >> t;
ll* arr = new ll[n];
for(ll i = 0; i < n; i++) cin >> arr[i];
if(t == 1 or t == 3 or t == 4 or t == 5)
cout << case1345(t, arr, n) << endl;
else cout << case267(t, arr, n) << endl;
return 0;
}