File tree Expand file tree Collapse file tree
OpenKattis/basicprogramming1 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <img src =" problem.png " />
Original file line number Diff line number Diff line change 1+ #include < bits/stdc++.h>
2+
3+ using namespace std ;
4+
5+ int main (){
6+ #define int long long
7+ int N, t; cin >> N >> t;
8+ int arr[N+5 ];
9+ int sum = 0 ;
10+ int even = 0 ;
11+ string alp = " abcdefghijklmnopqrstuvwxyz" ;
12+ string str = " " ;
13+ for (int i = 0 ; i < N; i++){
14+ int in;
15+ cin >> in;
16+ arr[i] = in;
17+ sum += in;
18+ if (in % 2 == 0 ){
19+ even += in;
20+ }
21+ str += alp[in % 26 ];
22+ }
23+ if (t == 1 ){
24+ cout << 7 << endl;
25+ } else if (t == 2 ){
26+ if (arr[0 ] > arr[1 ]){
27+ cout << " Bigger\n " ;
28+ } else if (arr[0 ] == arr[1 ]){
29+ cout << " Equal\n " ;
30+ } else {
31+ cout << " Smaller\n " ;
32+ }
33+ } else if (t == 3 ) {
34+ int arr1[] = {arr[0 ], arr[1 ], arr[2 ]};
35+ sort (arr1, arr1+3 );
36+ cout << arr1[1 ] << endl;
37+ } else if (t == 4 ){
38+ cout << sum << endl;
39+ } else if (t == 5 ){
40+ cout << even << endl;
41+ } else if (t == 6 ){
42+ cout << str << endl;
43+ } else {
44+ int index = 0 ;
45+ int count = 0 ;
46+ while (index < (N-1 ) && count++ <= N){
47+ // cout << "C: " << count << endl;
48+ index = arr[index];
49+ }
50+ if (index > (N-1 )){
51+ cout << " Out\n " ;
52+ } else if (index == (N-1 )){
53+ cout << " Done\n " ;
54+ } else {
55+ cout << " Cyclic\n " ;
56+ }
57+ }
58+ }
You can’t perform that action at this time.
0 commit comments