-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicprogramming1.cpp
More file actions
80 lines (78 loc) · 1.97 KB
/
Copy pathbasicprogramming1.cpp
File metadata and controls
80 lines (78 loc) · 1.97 KB
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
72
73
74
75
76
77
78
79
80
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
int N, t;
cin >> N >> t;
int A[N];
for(int i = 0; i < N; i += 1){
cin >> A[i];
}
if(t == 1){
cout << "7" << endl;
}
else if(t == 2){
if(A[0] > A[1]){
cout << "Bigger" << endl;
}
else if(A[0] == A[1]){
cout << "Equal" << endl;
}
else{
cout << "Smaller" << endl;
}
}
else if(t == 3){
int median = max(min(A[0], A[1]), min(max(A[0], A[1]), A[2]));
cout << median << endl;
}
else if(t == 4){
long long sum = 0;
for(int i = 0; i < N; i += 1){
sum += A[i];
}
cout << sum << endl;
}
else if(t == 5){
long long sum = 0;
for(int i = 0; i < N; i += 1){
if(A[i] % 2 == 0){
sum += A[i];
}
}
cout << sum << endl;
}
else if(t == 6){
char letters[26] = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
for(int i = 0; i < N; i += 1){
cout << letters[A[i] % 26];
}
}
else{
bool stopped = false;
int prev_index = 0;
int hops = 0;
int curr_index = A[prev_index];
while(!stopped){
hops += 1;
if(hops > N-1){
cout << "Cyclic" << endl;
stopped = true;
}
else{
curr_index = A[prev_index];
if(curr_index >= N){
cout << "Out" << endl;
stopped = true;
}
else if(curr_index == N-1){
cout << "Done" << endl;
stopped = true;
}
prev_index = curr_index;
}
}
}
return 0;
}