-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasicprogramming1.cpp
122 lines (113 loc) · 2.45 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <numeric>
#include <algorithm>
using namespace std;
void Func2(int32_t, int32_t);
void Func3(int32_t, int32_t, int32_t);
void Func4(int32_t[], int);
void Func5(int32_t[], int);
void Func6(int32_t[], int);
int Func7(int32_t[], int);
int main(){
int n, t;
cin >> n;
cin >> t;
int32_t A[n];
for (int i=0; i<n; i++){
cin >> A[i];
}
switch(t){
case 1:
cout << "7";
break;
case 2:
Func2(A[0],A[1]);
break;
case 3:
Func3(A[0],A[1],A[2]);
break;
case 4:
Func4(A, n);
break;
case 5:
Func5(A, n);
break;
case 6:
Func6(A, n);
break;
case 7:
Func7(A, n);
break;
}
return 0;
}
// Bigger, Equal or Smaller
void Func2(int32_t a, int32_t b){
if (a > b){
cout << "Bigger";
} else if (a == b){
cout << "Equal";
} else {
cout << "Smaller";
}
}
// Print the median of three integers
void Func3(int32_t a, int32_t b, int32_t c){
int32_t list[3] = {a, b, c};
bool swapped;
do {
swapped = false;
for (int i=0; i<2; i++){
if (list[i] > list[i+1]){
int32_t temp = list[i+1];
list[i+1] = list[i];
list[i] = temp;
swapped = true;
}
}
} while (swapped);
cout << list[1];
}
// Print the sum of all integers
void Func4(int32_t a[], int size){
int64_t sum = 0;
for (int i=0; i<size; i++){
sum += a[i];
}
cout << sum;
}
// Print the sum of all even integers
void Func5(int32_t a[], int size){
int64_t sum = 0;
for (int i=0; i<size; i++){
if (a[i] % 2 == 0){
sum += a[i];
}
}
cout << sum;
}
// Print the sequence of characters as a string
void Func6(int32_t a[], int size){
string charLib = "abcdefghijklmnopqrstuvwxyz";
for (int i=0; i<size; i++){
cout << charLib[(a[i]%26)];
}
}
int Func7(int32_t a[], int size){
int index = 0;
do{
if (index == size-1){
cout << "Done";
return 0;
}
int temp = a[index];
a[index] = -1;
index = temp;
} while (index >= 0 && index < size);
if (index == -1){
cout << "Cyclic";
return 0;
}
cout << "Out";
return 0;
}