Skip to content

Commit 9c0258a

Browse files
authored
Merge pull request div-bargali#863
Korean translation of Readme, Contributing and Code of Conduct files and comments added to some files.
2 parents bad62ef + e7a9b35 commit 9c0258a

15 files changed

+593
-9
lines changed

C++/Algorithms/Backtracking/Permutation_of_string.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using namespace std;
44
// Function to find all Permutations of a given string str[i..n-1]
55
// containing all distinct characters and which u want to change
66

7-
void permutations(string str, int i, int n,int j, int k )
7+
void permutations(string str, int i, int n)
88
{
99
// base condition
1010
if (i == n - 1)
@@ -35,4 +35,4 @@ int main()
3535
permutations(str, 0, str.length());
3636

3737
return 0;
38-
}
38+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
void printSolution(int** solution, int n) { //if we find out solution then print out full path
5+
for (int i = 0; i < n; i++) {
6+
for (int j = 0; j < n; j++) {
7+
cout << solution[i][j] << " ";
8+
}
9+
}
10+
cout << endl;
11+
}
12+
void mazeHelp(int maze[][20], int n, int** solution, int x, int y) { //
13+
14+
15+
if (x == n - 1 && y == n - 1) { //when x,y reaches the end of point
16+
solution[x][y] = 1;
17+
printSolution(solution, n);
18+
return;
19+
}
20+
if (x >= n || x < 0 || y >= n || y < 0 || maze[x][y] == 0 || solution[x][y] == 1) { //whether x,y is out of map or coordinate which can be used as a path
21+
return;
22+
}
23+
solution[x][y] = 1; //it has been used to solution path
24+
mazeHelp(maze, n, solution, x - 1, y);
25+
mazeHelp(maze, n, solution, x + 1, y);
26+
mazeHelp(maze, n, solution, x, y - 1);
27+
mazeHelp(maze, n, solution, x, y + 1);
28+
solution[x][y] = 0; //backtracking
29+
}
30+
31+
32+
void ratInAMaze(int maze[][20], int n) {
33+
int** solution = new int* [n];
34+
for (int i = 0; i < n; i++) {
35+
solution[i] = new int[n];
36+
}
37+
mazeHelp(maze, n, solution, 0, 0);
38+
}
39+
40+
41+
42+
int main() {
43+
44+
int n;
45+
cin >> n; //n representing dimension of the maze
46+
int maze[20][20];
47+
for (int i = 0; i < n; i++) {
48+
for (int j = 0; j < n; j++) {
49+
cin >> maze[i][j]; //n space-separated integers representing the type of the cell
50+
}
51+
}
52+
ratInAMaze(maze, n);
53+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
This function is a function that calculates the sum of the number of digits in the integer entered by the user by the number of digits in the entered integer.
3+
If the number is the same as the number initially entered, it prints that the Armstrong number is correct, and if it is different, it prints that it is not.
4+
*/
5+
#include <cmath>
6+
#include <iostream>
7+
8+
using namespace std;
9+
10+
int main() {
11+
int n, ognum, d, ct = 0, sum = 0, power;
12+
cout << "Enter an integer: ";
13+
cin >> n;
14+
15+
ognum = n;
16+
17+
while (ognum != 0) { // Finding the number of digits of the input integer
18+
ognum /= 10;
19+
++ct;
20+
}
21+
ognum = n;
22+
23+
while (ognum != 0) { // Square the numbers in each digit by the number of digits in the input integer. Then, the squared numbers are added together
24+
d = ognum % 10;
25+
power = round(pow(d, ct));
26+
sum += power;
27+
ognum /= 10;
28+
}
29+
30+
if (sum == n) // Armstrong's number if the sum of the number of digits from the inputted integers squared by the number of digits received is equal to the number initially input
31+
cout << n << " is an Armstrong number.";
32+
else // If it's wrong, it's not Armstrong's number.
33+
cout << n << " is not an Armstrong number.";
34+
return 0;
35+
}

C++/Algorithms/Mathematical/Lucky_number.cpp renamed to C++/Algorithms/Mathematical/Lucky_number_comment.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
This function receives the value of n1 from the user, and outputs a "lucky number"
3+
if there is a duplicate number among the input numbers, and a "not lucky number" if there is no duplicate number.
4+
*/
5+
16
#include<iostream>
27
using namespace std;
38

@@ -7,10 +12,10 @@ int main() {
712
cin>>n1;
813
n2=n1;
914
n=n1;
10-
while(n1>0)
15+
while(n1>0)
1116
{
1217
d1=n1%10;
13-
while(n2>0)
18+
while(n2>0)
1419
{
1520
d2=n2%10;
1621
if(d1==d2)
@@ -26,9 +31,9 @@ int main() {
2631
n2=n;
2732
n1=n1/10;
2833
}
29-
if(flag==1)
34+
if(flag==1) // flag == 1 it means that the numbers do overlap
3035
cout<<n<<" is not a lucky number";
31-
else
36+
else // flag != 1 it means that there is even one duplicate number
3237
cout<<n<<" is a lucky number";
3338
return 0;
3439
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
void printArray(int array[], int size) {
4+
for (int i = 0; i < size; ++i) {
5+
cout << array[i] << " "; //print array
6+
}
7+
cout << endl;
8+
}
9+
void shiftArray(int array[], int size) {
10+
int left = 0, right = size-1;
11+
while(left <= right) { //sorting
12+
if(array[left] < 0 && array[right] < 0) {
13+
left++;
14+
}
15+
else if(array[left] < 0 && array[right] > 0) {
16+
right--;
17+
}
18+
else if(array[left] > 0 && array[right] < 0) {
19+
swap(array[left], array[right]);
20+
right--;
21+
left++;
22+
}
23+
else {
24+
right--;
25+
}
26+
}
27+
}
28+
int main() {
29+
int size;
30+
cout << "Enter the size of array:\n";
31+
cin >> size; //input size
32+
int array[size];
33+
cout << "Enter the elements of the array:\n";
34+
for(int i = 0; i < size; ++i) {
35+
cin >> array[i]; //input value
36+
}
37+
cout << "Original Array:\t";
38+
printArray(array, size); //print original array
39+
cout << "After moving all negative elements to left:\t";
40+
shiftArray(array, size); //Run sorting function
41+
printArray(array, size); //print shift array
42+
return 0;
43+
}
44+
45+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <iostream>
2+
using namespace std;
3+
#define ll long long int
4+
#define MAXSIZE 100
5+
6+
int main() {
7+
ll arr[MAXSIZE] = {NULL, } ,i=0;
8+
while(cin>>arr[i]){
9+
i++; //input value (if value is ^z[ctrl + z] break while)
10+
}
11+
ll n = i;
12+
13+
ll pos[MAXSIZE],neg[MAXSIZE];
14+
ll pi=0,pn=0,xp=0,xn=0;
15+
for(i=0;i<n;i++){ //first sorting
16+
if(arr[i] >= 0){
17+
pos[pi] = arr[i]; //positive number = pos[]
18+
pi++;
19+
}
20+
else{
21+
neg[pn] = arr[i]; //negative number = neg[]
22+
pn++;
23+
}
24+
}
25+
for(i=0;i<n;i++){ //second sorting
26+
if(i%2==0 && xp<pi){
27+
arr[i] = pos[xp]; //if i = even and xp < pi
28+
xp++;
29+
}
30+
else if(i%2!=0 && xn<pn){//else if i = odd and xn < pn
31+
arr[i] = neg[xn];
32+
xn++;
33+
}
34+
else if(xp>=pi){ //else if xp >= pi
35+
arr[i] = neg[xn++];
36+
}
37+
else if(xn>=pn){
38+
arr[i] = pos[xp++]; //else if xn >= pn
39+
}
40+
}
41+
42+
for(i=0;i<n;i++){
43+
cout<<arr[i]<<" "; //print Array completed sorting
44+
}
45+
return 0;
46+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length.
2+
3+
Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.
4+
Only adjacent values are deleted.
5+
ex) 12333333
6+
= 123
7+
ex2)
8+
1234512345
9+
= 1234512345
10+
11+
*/
12+
#include<bits/stdc++.h>
13+
using namespace std;
14+
int removeDuplicates(vector<int>& nums) // this function returns length
15+
{
16+
int l = 0, i, c = 0;
17+
18+
for (i = 0; i < nums.size(); i++) // l stores the number of distcinct elements in the array
19+
{
20+
if (i == 0)
21+
{
22+
l++; continue;
23+
}
24+
if (nums[i] == nums[i - 1])
25+
continue;
26+
else
27+
l++;
28+
}
29+
for (i = 0; i < nums.size(); i++)
30+
{
31+
if (i == 0)
32+
{
33+
c++; continue;
34+
}
35+
if (nums[i] != nums[i - 1]) //as soon a new element is encountered it is paced at index c
36+
{
37+
nums[c] = nums[i];
38+
c++;
39+
if (c == l) //it checks all the distcinct elements have been alloted in the first l indices
40+
break;
41+
}
42+
}
43+
return l;
44+
}
45+
int main()
46+
{
47+
vector<int> nums;
48+
int n, i;
49+
cin >> n;
50+
for (i = 0; i < n; i++) //takes input fro/m user
51+
{
52+
int b;
53+
cin >> b;
54+
nums.push_back(b);
55+
}
56+
int len = removeDuplicates(nums);
57+
for (i = 0; i < len; i++) //prints the required distinct elements
58+
cout << nums[i] << " ";
59+
return 0;
60+
}

0 commit comments

Comments
 (0)