Skip to content

Commit d489c5d

Browse files
committed
local
1 parent de092c7 commit d489c5d

13 files changed

+400
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
*/
3+
4+
#include<iostream>
5+
using namespace std;
6+
7+
int main() {
8+
int start, end;
9+
10+
cin>>start>>end;
11+
12+
while(start <= end)
13+
{
14+
cout<<start<<"\n";
15+
start++;
16+
}
17+
18+
return 0;
19+
}
20+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
*/
3+
4+
#include<iostream>
5+
using namespace std;
6+
7+
int main() {
8+
int num;
9+
char ch;
10+
11+
cin>>num>>ch;
12+
13+
while(num > 0)
14+
{
15+
cout<<ch;
16+
num -= 1;
17+
}
18+
19+
return 0;
20+
}
21+
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
*
3+
*/
4+
5+
#include<iostream>
6+
using namespace std;
7+
8+
int main() {
9+
int N;
10+
11+
cin >> N;
12+
13+
int row = 1;
14+
while (row <= N) {
15+
int stars_count = 1;
16+
17+
while (stars_count <= row) {
18+
cout << '*';
19+
++stars_count;
20+
}
21+
cout << "\n";
22+
row++;
23+
}
24+
25+
return 0;
26+
}
27+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
*/
3+
4+
#include<iostream>
5+
using namespace std;
6+
7+
int main() {
8+
int N;
9+
10+
cin >> N;
11+
12+
int row = N;
13+
while (row > 0) {
14+
int stars_count = 1;
15+
16+
while (stars_count <= row) {
17+
cout << '*';
18+
++stars_count;
19+
}
20+
cout << "\n";
21+
row--;
22+
}
23+
24+
return 0;
25+
}
26+
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Homework 5: Print diamond
3+
*
4+
* Given a number N. Print diamond of 2N rows as in.
5+
* https://codeforces.com/group/MWSDmqGsZm/contest/219432/problem/X
6+
*/
7+
8+
#include<iostream>
9+
using namespace std;
10+
11+
int main() {
12+
int N;
13+
14+
cin >> N;
15+
16+
/*
17+
* Let's print the upper triangle first
18+
* Let's assume N = 4, how many spaces and starts we print
19+
* Row 1 Spaces 3 Stars 1
20+
* Row 2 Spaces 2 Stars 3
21+
* Row 3 Spaces 1 Stars 5
22+
* Row 4 Spaces 0 Stars 7
23+
*
24+
* Now we wanna develop formulas for number of spaces and number of starts
25+
* For a given 'row'
26+
* Spaces are: N - rows (3, 2, 1, 0)
27+
* Starts are: 2*row -1 (1, 3, 5, 7)
28+
*
29+
* Now we just iterate for each row
30+
* print spaces
31+
* then print starts
32+
*/
33+
int row = 1;
34+
while (row <= N) {
35+
int stars_count = 1;
36+
37+
// Print N - rows spaces
38+
while (stars_count <= N-row) {
39+
cout << ' ';
40+
++stars_count;
41+
}
42+
43+
// Print 2*rows-1 stars
44+
stars_count = 1;
45+
while (stars_count <= 2*row-1) {
46+
cout << '*';
47+
++stars_count;
48+
}
49+
cout << "\n";
50+
++row;
51+
}
52+
53+
/*
54+
* Let's print the lower triangle second
55+
* Same logic, we just switch looping from N to 1
56+
*/
57+
row = N;
58+
while (row >= 1) {
59+
int stars_count = 1;
60+
61+
while (stars_count <= N-row) {
62+
cout << ' ';
63+
++stars_count;
64+
}
65+
66+
stars_count = 1;
67+
68+
while (stars_count <= 2*row-1) {
69+
cout << '*';
70+
++stars_count;
71+
}
72+
cout << "\n";
73+
--row;
74+
}
75+
return 0;
76+
}
77+
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
2+
3+
/*
4+
*
5+
* Test cases
6+
* Input: 7 11 101 21 201 31 602 78
7+
*
8+
* Output: 35.25 301.333
9+
*/
10+
11+
#include<iostream>
12+
using namespace std;
13+
14+
int main() {
15+
int N;
16+
17+
cin >> N;
18+
19+
// Use doubles to: 1) allow any values 2) get average correctly
20+
double even_sum = 0, odd_sum = 0;
21+
int even_count = 0, odd_count = 0;
22+
23+
int cnt = 1;
24+
while (cnt <= N) {
25+
double value;
26+
cin >> value;
27+
28+
if (cnt % 2 == 0) // even position
29+
even_sum += value, even_count++;
30+
else // odd position
31+
odd_sum += value, odd_count++;
32+
33+
cnt++;
34+
}
35+
36+
cout <<odd_sum / odd_count << " " << even_sum / even_count << "\n";
37+
38+
return 0;
39+
}
40+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int N, result = 0;
6+
7+
cin >> N;
8+
9+
int cnt = 0;
10+
11+
while (cnt <= N)
12+
{
13+
if (cnt % 8 == 0 || cnt % 3 == 0 && cnt % 4 == 0)
14+
cout<<cnt<<" ";
15+
16+
cnt ++;
17+
}
18+
19+
20+
21+
22+
return 0;
23+
}
24+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int N, result = 0;
6+
7+
cin >> N;
8+
9+
int cnt = 0;
10+
int current_number = 0;
11+
12+
while (cnt <= N) {
13+
if (current_number % 3 == 0 && current_number % 4 != 0) {
14+
cout << current_number << " ";
15+
cnt++;
16+
}
17+
current_number++;
18+
}
19+
return 0;
20+
}
21+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int N;
6+
7+
cin >> N;
8+
9+
int pos = 0;
10+
11+
while (pos < N) {
12+
string str;
13+
cin>>str;
14+
15+
// there are 8 different ways to make 2 letters no in lower/upper cases
16+
if (str == "no" || str == "No" || str == "nO" || str == "NO" ||
17+
str == "on" || str == "oN" || str == "On" || str == "ON")
18+
cout<<str<<" ";
19+
20+
pos++;
21+
}
22+
return 0;
23+
}
24+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include<iostream>
2+
using namespace std;
3+
4+
int main() {
5+
int N;
6+
7+
cin >> N;
8+
9+
int number = 0;
10+
11+
while (N > 0) {
12+
int last_digits = N % 10;
13+
N /= 10; // remove last digit
14+
15+
number = number * 10 + last_digits;
16+
}
17+
cout << number << " " << number * 3 << "\n";
18+
19+
return 0;
20+
}
21+

0 commit comments

Comments
 (0)