rename Others -> others (#648)

* rename Others -> temp

* rename Others -> others
This commit is contained in:
Christian Clauss 2019-11-28 13:29:54 +01:00 committed by GitHub
parent 6fe40bd0a2
commit ac1ba3a613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 141 additions and 141 deletions

View File

@ -1,63 +1,63 @@
#include<iostream>
using namespace std;
void show_pascal(int **arr, int n)
{
//pint Pascal's Triangle
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n + i; ++j)
{
if (arr[i][j] == 0)
cout << " ";
else
cout << arr[i][j];
}
cout << endl;
}
}
int **pascal_triangle(int **arr, int n)
{
for (int i = 0; i < n; ++i)
{
for (int j = n - i - 1; j < n + i; ++j)
{
if (j == n - i - 1 || j == n + i - 1)
arr[i][j] = 1; //The edge of the Pascal triangle goes in 1
else
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j + 1];
}
}
return arr;
}
int main()
{
int n = 0;
cout << "Set Pascal's Triangle Height" << endl;
cin >> n;
//memory allocation (Assign two-dimensional array to store Pascal triangle)
int **arr = new int*[n];
for (int i = 0; i < n; ++i)
{
arr[i] = new int[2 * n - 1];
memset(arr[i], 0, sizeof(int)*(2 * n - 1));
}
pascal_triangle(arr, n);
show_pascal(arr, n);
//deallocation
for (int i = 0; i < n; ++i)
{
delete[] arr[i];
}
delete[] arr;
return 0;
}
#include<iostream>
using namespace std;
void show_pascal(int **arr, int n)
{
//pint Pascal's Triangle
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < n + i; ++j)
{
if (arr[i][j] == 0)
cout << " ";
else
cout << arr[i][j];
}
cout << endl;
}
}
int **pascal_triangle(int **arr, int n)
{
for (int i = 0; i < n; ++i)
{
for (int j = n - i - 1; j < n + i; ++j)
{
if (j == n - i - 1 || j == n + i - 1)
arr[i][j] = 1; //The edge of the Pascal triangle goes in 1
else
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j + 1];
}
}
return arr;
}
int main()
{
int n = 0;
cout << "Set Pascal's Triangle Height" << endl;
cin >> n;
//memory allocation (Assign two-dimensional array to store Pascal triangle)
int **arr = new int*[n];
for (int i = 0; i < n; ++i)
{
arr[i] = new int[2 * n - 1];
memset(arr[i], 0, sizeof(int)*(2 * n - 1));
}
pascal_triangle(arr, n);
show_pascal(arr, n);
//deallocation
for (int i = 0; i < n; ++i)
{
delete[] arr[i];
}
delete[] arr;
return 0;
}

View File

@ -1,78 +1,78 @@
#include <iostream>
using namespace std;
void genArray(int a[][10], int r, int c)
{
int value = 1;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
a[i][j] = value;
cout << a[i][j] << " ";
value++;
}
cout << endl;
}
}
void spiralPrint(int a[][10], int r, int c)
{
int startRow = 0, endRow = r - 1;
int startCol = 0, endCol = c - 1;
int cnt = 0;
while (startRow <= endRow && startCol <= endCol)
{
///Print start row
for (int i = startCol; i <= endCol; i++, cnt++)
{
cout << a[startRow][i] << " ";
}
startRow++;
///Print the end col
for (int i = startRow; i <= endRow; i++, cnt++)
{
cout << a[i][endCol] << " ";
}
endCol--;
///Print the end row
if (cnt == r * c)
{
break;
}
for (int i = endCol; i >= startCol; i--, cnt++)
{
cout << a[endRow][i] << " ";
}
endRow--;
///Print the start Col
if (cnt == r * c)
{
break;
}
for (int i = endRow; i >= startRow; i--, cnt++)
{
cout << a[i][startCol] << " ";
}
startCol++;
}
}
int main()
{
int a[10][10];
int r, c;
cin >> r >> c;
genArray(a, r, c);
spiralPrint(a, r, c);
return 0;
}
#include <iostream>
using namespace std;
void genArray(int a[][10], int r, int c)
{
int value = 1;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
a[i][j] = value;
cout << a[i][j] << " ";
value++;
}
cout << endl;
}
}
void spiralPrint(int a[][10], int r, int c)
{
int startRow = 0, endRow = r - 1;
int startCol = 0, endCol = c - 1;
int cnt = 0;
while (startRow <= endRow && startCol <= endCol)
{
///Print start row
for (int i = startCol; i <= endCol; i++, cnt++)
{
cout << a[startRow][i] << " ";
}
startRow++;
///Print the end col
for (int i = startRow; i <= endRow; i++, cnt++)
{
cout << a[i][endCol] << " ";
}
endCol--;
///Print the end row
if (cnt == r * c)
{
break;
}
for (int i = endCol; i >= startCol; i--, cnt++)
{
cout << a[endRow][i] << " ";
}
endRow--;
///Print the start Col
if (cnt == r * c)
{
break;
}
for (int i = endRow; i >= startRow; i--, cnt++)
{
cout << a[i][startCol] << " ";
}
startCol++;
}
}
int main()
{
int a[10][10];
int r, c;
cin >> r >> c;
genArray(a, r, c);
spiralPrint(a, r, c);
return 0;
}