Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aa8ebe0

Browse files
committed
Add Solution for basicprogramming1 [OpenKattis]
1 parent 132c4ba commit aa8ebe0

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

‎OpenKattis/basicprogramming1/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<img src="problem.png" />
292 KB
Loading[フレーム]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /