Skip to content

Commit 8799a52

Browse files
committed
Update
1 parent 9ac4ba4 commit 8799a52

30 files changed

+364
-364
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
/* -------------------------------------------------------------------------- */
2-
/* Add Natural Numbers Problem Code: ADDNATRL */
3-
/* -------------------------------------------------------------------------- */
4-
5-
/**You are given a number N. Find the sum of all numbers from 1 to N.
6-
*/
7-
8-
/*
9-
Input:
10-
First-line will contain the number N.
11-
12-
Output:
13-
Print the answer in a single line.
14-
15-
Constraints
16-
1≤N≤109
17-
18-
Sample Input 1:
19-
4
20-
21-
Sample Output 1:
22-
10
23-
24-
Sample Input 2:
25-
8
26-
27-
Sample Output 2:
28-
36
29-
30-
EXPLANATION:
31-
In the first example, (1 + 2 + 3 + 4) = 10.
32-
In the second example, (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) = 36.
33-
*/
34-
35-
#include <iostream>
36-
using namespace std;
37-
38-
int main()
39-
{
40-
long int N, R; //10^9
41-
cin >> N;
42-
R = (N / 2) * (2 + (N - 1));
43-
cout << R;
44-
return 0;
1+
/* -------------------------------------------------------------------------- */
2+
/* Add Natural Numbers Problem Code: ADDNATRL */
3+
/* -------------------------------------------------------------------------- */
4+
5+
/**You are given a number N. Find the sum of all numbers from 1 to N.
6+
*/
7+
8+
/*
9+
Input:
10+
First-line will contain the number N.
11+
12+
Output:
13+
Print the answer in a single line.
14+
15+
Constraints
16+
1≤N≤109
17+
18+
Sample Input 1:
19+
4
20+
21+
Sample Output 1:
22+
10
23+
24+
Sample Input 2:
25+
8
26+
27+
Sample Output 2:
28+
36
29+
30+
EXPLANATION:
31+
In the first example, (1 + 2 + 3 + 4) = 10.
32+
In the second example, (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8) = 36.
33+
*/
34+
35+
#include <iostream>
36+
using namespace std;
37+
38+
int main()
39+
{
40+
long int N, R; //10^9
41+
cin >> N;
42+
R = (N / 2) * (2 + (N - 1));
43+
cout << R;
44+
return 0;
4545
}
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,91 @@
1-
/* -------------------------------------------------------------------------- */
2-
/* Alternative Square Pattern Problem Code: SQALPAT */
3-
/* -------------------------------------------------------------------------- */
4-
5-
/**You're given a number N. Print the first N lines of the below-given pattern.
6-
7-
1 2 3 4 5
8-
10 9 8 7 6
9-
11 12 13 14 15
10-
20 19 18 17 16
11-
21 22 23 24 25
12-
30 29 28 27 26
13-
14-
*/
15-
16-
/*
17-
Input:
18-
First-line will contain the number N.
19-
20-
Output:
21-
Print the first N lines of the given pattern.
22-
23-
Constraints
24-
1≤N≤200
25-
26-
Sample Input 1:
27-
4
28-
29-
Sample Output 1:
30-
1 2 3 4 5
31-
10 9 8 7 6
32-
11 12 13 14 15
33-
20 19 18 17 16
34-
35-
Sample Input 2:
36-
2
37-
38-
Sample Output 2:
39-
1 2 3 4 5
40-
10 9 8 7 6
41-
42-
EXPLANATION:
43-
In the first example, we'll print the first 4 lines of the given pattern.
44-
In the second example, we'll print the first 2 lines of the given pattern.
45-
*/
46-
47-
// #include <iostream>
48-
// using namespace std;
49-
50-
// int main()
51-
// {
52-
// int N, show, j = 1, k = 1;
53-
// cin >> N;
54-
// for (int i = 0; i < N; i++)
55-
// {
56-
// for (j = k; j <= (i + 1) * 5; j++)
57-
// cout << j << " ";
58-
// cout << endl;
59-
// for (k = (i + 2) * 5; k >= j; k--)
60-
// cout << k << " ";
61-
// cout << endl;
62-
// }
63-
// cin >> show;
64-
// return 0;
65-
// }
66-
67-
#include <iostream>
68-
using namespace std;
69-
70-
int main()
71-
{
72-
int N, j = 1, k;
73-
cin >> N;
74-
for (int i = 1; i <= N; i++)
75-
{
76-
if (i % 2 == 1 || i == 1)
77-
{
78-
for (; j <= i * 5; j++)
79-
cout << j << " ";
80-
cout << endl;
81-
}
82-
else
83-
{
84-
for (int k = i * 5; k >= j; k--)
85-
cout << k << " ";
86-
cout << endl;
87-
}
88-
j = (i*5)+1;
89-
}
90-
return 0;
1+
/* -------------------------------------------------------------------------- */
2+
/* Alternative Square Pattern Problem Code: SQALPAT */
3+
/* -------------------------------------------------------------------------- */
4+
5+
/**You're given a number N. Print the first N lines of the below-given pattern.
6+
7+
1 2 3 4 5
8+
10 9 8 7 6
9+
11 12 13 14 15
10+
20 19 18 17 16
11+
21 22 23 24 25
12+
30 29 28 27 26
13+
14+
*/
15+
16+
/*
17+
Input:
18+
First-line will contain the number N.
19+
20+
Output:
21+
Print the first N lines of the given pattern.
22+
23+
Constraints
24+
1≤N≤200
25+
26+
Sample Input 1:
27+
4
28+
29+
Sample Output 1:
30+
1 2 3 4 5
31+
10 9 8 7 6
32+
11 12 13 14 15
33+
20 19 18 17 16
34+
35+
Sample Input 2:
36+
2
37+
38+
Sample Output 2:
39+
1 2 3 4 5
40+
10 9 8 7 6
41+
42+
EXPLANATION:
43+
In the first example, we'll print the first 4 lines of the given pattern.
44+
In the second example, we'll print the first 2 lines of the given pattern.
45+
*/
46+
47+
// #include <iostream>
48+
// using namespace std;
49+
50+
// int main()
51+
// {
52+
// int N, show, j = 1, k = 1;
53+
// cin >> N;
54+
// for (int i = 0; i < N; i++)
55+
// {
56+
// for (j = k; j <= (i + 1) * 5; j++)
57+
// cout << j << " ";
58+
// cout << endl;
59+
// for (k = (i + 2) * 5; k >= j; k--)
60+
// cout << k << " ";
61+
// cout << endl;
62+
// }
63+
// cin >> show;
64+
// return 0;
65+
// }
66+
67+
#include <iostream>
68+
using namespace std;
69+
70+
int main()
71+
{
72+
int N, j = 1, k;
73+
cin >> N;
74+
for (int i = 1; i <= N; i++)
75+
{
76+
if (i % 2 == 1 || i == 1)
77+
{
78+
for (; j <= i * 5; j++)
79+
cout << j << " ";
80+
cout << endl;
81+
}
82+
else
83+
{
84+
for (int k = i * 5; k >= j; k--)
85+
cout << k << " ";
86+
cout << endl;
87+
}
88+
j = (i*5)+1;
89+
}
90+
return 0;
9191
}
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
1-
/* -------------------------------------------------------------------------- */
2-
/* Buy Please Problem Code: BUYPLSE */
3-
/* -------------------------------------------------------------------------- */
4-
5-
/**Chef went to a shop and buys a pens and b pencils.
6-
* Each pen costs x units and each pencil costs y units.
7-
* Now find what is the total amount Chef will spend to buy a pens and b pencils.
8-
*/
9-
10-
/*
11-
Input:
12-
First-line will contain 4 space separated integers a, b, x and y respectively.
13-
14-
Output:
15-
Print the answer in a new line.
16-
17-
Constraints
18-
1≤a,b,x,y≤10^3
19-
20-
Sample Input 1:
21-
2 4 4 5
22-
23-
Sample Output 1:
24-
28
25-
26-
Sample Input 2:
27-
1 1 4 8
28-
29-
Sample Output 2:
30-
12
31-
32-
EXPLANATION:
33-
In the first example, total cost is (2 * 4 + 4 * 5) = 28.
34-
In the second example, total cost is (1 * 4 + 1 * 8) = 12.
35-
*/
36-
37-
#include <iostream>
38-
using namespace std;
39-
40-
int main()
41-
{
42-
int a, b, x, y;
43-
cin >> a >> b >> x >> y;
44-
cout << ((a * x) + (b * y));
45-
return 0;
1+
/* -------------------------------------------------------------------------- */
2+
/* Buy Please Problem Code: BUYPLSE */
3+
/* -------------------------------------------------------------------------- */
4+
5+
/**Chef went to a shop and buys a pens and b pencils.
6+
* Each pen costs x units and each pencil costs y units.
7+
* Now find what is the total amount Chef will spend to buy a pens and b pencils.
8+
*/
9+
10+
/*
11+
Input:
12+
First-line will contain 4 space separated integers a, b, x and y respectively.
13+
14+
Output:
15+
Print the answer in a new line.
16+
17+
Constraints
18+
1≤a,b,x,y≤10^3
19+
20+
Sample Input 1:
21+
2 4 4 5
22+
23+
Sample Output 1:
24+
28
25+
26+
Sample Input 2:
27+
1 1 4 8
28+
29+
Sample Output 2:
30+
12
31+
32+
EXPLANATION:
33+
In the first example, total cost is (2 * 4 + 4 * 5) = 28.
34+
In the second example, total cost is (1 * 4 + 1 * 8) = 12.
35+
*/
36+
37+
#include <iostream>
38+
using namespace std;
39+
40+
int main()
41+
{
42+
int a, b, x, y;
43+
cin >> a >> b >> x >> y;
44+
cout << ((a * x) + (b * y));
45+
return 0;
4646
}

0 commit comments

Comments
 (0)