Skip to content

Commit ac1ba3a

Browse files
authored
rename Others -> others (#648)
* rename Others -> temp * rename Others -> others
1 parent 6fe40bd commit ac1ba3a

19 files changed

+141
-141
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
1-
#include<iostream>
2-
3-
using namespace std;
4-
5-
void show_pascal(int **arr, int n)
6-
{
7-
//pint Pascal's Triangle
8-
for (int i = 0; i < n; ++i)
9-
{
10-
for (int j = 0; j < n + i; ++j)
11-
{
12-
if (arr[i][j] == 0)
13-
cout << " ";
14-
else
15-
cout << arr[i][j];
16-
}
17-
cout << endl;
18-
}
19-
}
20-
21-
int **pascal_triangle(int **arr, int n)
22-
{
23-
for (int i = 0; i < n; ++i)
24-
{
25-
for (int j = n - i - 1; j < n + i; ++j)
26-
{
27-
if (j == n - i - 1 || j == n + i - 1)
28-
arr[i][j] = 1; //The edge of the Pascal triangle goes in 1
29-
else
30-
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j + 1];
31-
}
32-
}
33-
34-
return arr;
35-
}
36-
37-
int main()
38-
{
39-
int n = 0;
40-
41-
cout << "Set Pascal's Triangle Height" << endl;
42-
cin >> n;
43-
44-
//memory allocation (Assign two-dimensional array to store Pascal triangle)
45-
int **arr = new int*[n];
46-
for (int i = 0; i < n; ++i)
47-
{
48-
arr[i] = new int[2 * n - 1];
49-
memset(arr[i], 0, sizeof(int)*(2 * n - 1));
50-
}
51-
52-
pascal_triangle(arr, n);
53-
show_pascal(arr, n);
54-
55-
//deallocation
56-
for (int i = 0; i < n; ++i)
57-
{
58-
delete[] arr[i];
59-
}
60-
delete[] arr;
61-
62-
return 0;
63-
}
1+
#include<iostream>
2+
3+
using namespace std;
4+
5+
void show_pascal(int **arr, int n)
6+
{
7+
//pint Pascal's Triangle
8+
for (int i = 0; i < n; ++i)
9+
{
10+
for (int j = 0; j < n + i; ++j)
11+
{
12+
if (arr[i][j] == 0)
13+
cout << " ";
14+
else
15+
cout << arr[i][j];
16+
}
17+
cout << endl;
18+
}
19+
}
20+
21+
int **pascal_triangle(int **arr, int n)
22+
{
23+
for (int i = 0; i < n; ++i)
24+
{
25+
for (int j = n - i - 1; j < n + i; ++j)
26+
{
27+
if (j == n - i - 1 || j == n + i - 1)
28+
arr[i][j] = 1; //The edge of the Pascal triangle goes in 1
29+
else
30+
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j + 1];
31+
}
32+
}
33+
34+
return arr;
35+
}
36+
37+
int main()
38+
{
39+
int n = 0;
40+
41+
cout << "Set Pascal's Triangle Height" << endl;
42+
cin >> n;
43+
44+
//memory allocation (Assign two-dimensional array to store Pascal triangle)
45+
int **arr = new int*[n];
46+
for (int i = 0; i < n; ++i)
47+
{
48+
arr[i] = new int[2 * n - 1];
49+
memset(arr[i], 0, sizeof(int)*(2 * n - 1));
50+
}
51+
52+
pascal_triangle(arr, n);
53+
show_pascal(arr, n);
54+
55+
//deallocation
56+
for (int i = 0; i < n; ++i)
57+
{
58+
delete[] arr[i];
59+
}
60+
delete[] arr;
61+
62+
return 0;
63+
}
File renamed without changes.
File renamed without changes.
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,78 @@
1-
#include <iostream>
2-
using namespace std;
3-
4-
void genArray(int a[][10], int r, int c)
5-
{
6-
7-
int value = 1;
8-
for (int i = 0; i < r; i++)
9-
{
10-
for (int j = 0; j < c; j++)
11-
{
12-
a[i][j] = value;
13-
cout << a[i][j] << " ";
14-
value++;
15-
}
16-
cout << endl;
17-
}
18-
}
19-
void spiralPrint(int a[][10], int r, int c)
20-
{
21-
22-
int startRow = 0, endRow = r - 1;
23-
int startCol = 0, endCol = c - 1;
24-
int cnt = 0;
25-
26-
while (startRow <= endRow && startCol <= endCol)
27-
{
28-
29-
///Print start row
30-
for (int i = startCol; i <= endCol; i++, cnt++)
31-
{
32-
cout << a[startRow][i] << " ";
33-
}
34-
startRow++;
35-
36-
///Print the end col
37-
for (int i = startRow; i <= endRow; i++, cnt++)
38-
{
39-
cout << a[i][endCol] << " ";
40-
}
41-
endCol--;
42-
43-
///Print the end row
44-
if (cnt == r * c)
45-
{
46-
break;
47-
}
48-
49-
for (int i = endCol; i >= startCol; i--, cnt++)
50-
{
51-
cout << a[endRow][i] << " ";
52-
}
53-
endRow--;
54-
55-
///Print the start Col
56-
if (cnt == r * c)
57-
{
58-
break;
59-
}
60-
for (int i = endRow; i >= startRow; i--, cnt++)
61-
{
62-
cout << a[i][startCol] << " ";
63-
}
64-
startCol++;
65-
}
66-
}
67-
68-
int main()
69-
{
70-
int a[10][10];
71-
72-
int r, c;
73-
cin >> r >> c;
74-
genArray(a, r, c);
75-
spiralPrint(a, r, c);
76-
77-
return 0;
78-
}
1+
#include <iostream>
2+
using namespace std;
3+
4+
void genArray(int a[][10], int r, int c)
5+
{
6+
7+
int value = 1;
8+
for (int i = 0; i < r; i++)
9+
{
10+
for (int j = 0; j < c; j++)
11+
{
12+
a[i][j] = value;
13+
cout << a[i][j] << " ";
14+
value++;
15+
}
16+
cout << endl;
17+
}
18+
}
19+
void spiralPrint(int a[][10], int r, int c)
20+
{
21+
22+
int startRow = 0, endRow = r - 1;
23+
int startCol = 0, endCol = c - 1;
24+
int cnt = 0;
25+
26+
while (startRow <= endRow && startCol <= endCol)
27+
{
28+
29+
///Print start row
30+
for (int i = startCol; i <= endCol; i++, cnt++)
31+
{
32+
cout << a[startRow][i] << " ";
33+
}
34+
startRow++;
35+
36+
///Print the end col
37+
for (int i = startRow; i <= endRow; i++, cnt++)
38+
{
39+
cout << a[i][endCol] << " ";
40+
}
41+
endCol--;
42+
43+
///Print the end row
44+
if (cnt == r * c)
45+
{
46+
break;
47+
}
48+
49+
for (int i = endCol; i >= startCol; i--, cnt++)
50+
{
51+
cout << a[endRow][i] << " ";
52+
}
53+
endRow--;
54+
55+
///Print the start Col
56+
if (cnt == r * c)
57+
{
58+
break;
59+
}
60+
for (int i = endRow; i >= startRow; i--, cnt++)
61+
{
62+
cout << a[i][startCol] << " ";
63+
}
64+
startCol++;
65+
}
66+
}
67+
68+
int main()
69+
{
70+
int a[10][10];
71+
72+
int r, c;
73+
cin >> r >> c;
74+
genArray(a, r, c);
75+
spiralPrint(a, r, c);
76+
77+
return 0;
78+
}

0 commit comments

Comments
 (0)