-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPE1_EXAM.cpp
121 lines (87 loc) · 1.83 KB
/
PE1_EXAM.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
#include <bits/stdc++.h>
using namespace std;
char nth_letter(long long x){
char symbol = (char)('a' + (x%26));
return symbol;
}
int main(void){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n; //no. of integers
int t; // the value determines what is done
vector <long long> number;
cin >> n >> t;
//To input in values
for(int i=0; i<n; i++){
long long value;
cin >> value;
number.push_back(value);
}
if(t == 1){
cout << "7" << endl;
}
else if (t == 2){
if(number[0] > number[1]){
cout << "Bigger" <<endl;
}
else if(number[0] == number[1]){
cout << "Equal" <<endl;
}
else
cout << "Smaller" << endl;
}
else if (t == 3){
//NEED TO SORT THIS!!!
sort(number.begin(), number.end() + 3);
cout << number[1];
}
else if (t == 4){
long long sum = 0;
for(int i=0; i<number.size(); i++){
sum += number[i];
}
cout << sum << endl;
}
else if (t == 5){
long long sum = 0;
for(int i=0; i<number.size(); i++){
if(number[i] % 2 == 0){
sum += number[i];
}
}
cout << sum << endl;
}
else if (t == 6){
vector <char> alphabet;
for(int i=0; i<number.size(); i++){
char value;
value = nth_letter(number[i]);
alphabet.push_back(value);
}
for(auto v:alphabet){
cout << v;
}
}
else if (t==7){
long long value;
long long counter = 0;
value = number[0];
while(value < n && counter <= n){
value = number[value];
counter++;
if(value == n-1){
cout <<"Done" << endl;
return 0; // stop everything
}
}
if (value > n-1){
cout << "Out" << endl;
return 0;
}
else{
cout << "Cyclic" << endl;
return 0;
}
}
return 0;
}