Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions Arrays/rotateArray.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include<bits/stdc++.h>
using namespace std;


// } Driver Code Ends
class Solution{
public:

//Function to rotate an array by d elements in counter-clockwise direction.
void rotateArr(int arr[], int d, int n){
int temp[n];
int j=0;
for(int i=d;i<n;i++){
temp[j]=arr[i];
j++;
}
for(int i=0;i<d;i++){
temp[j]=arr[i];
j++;
}
j=0;
for(int i=0;i<n;i++){
arr[i]=temp[j];
j++;
}
}
};

// { Driver Code Starts.

int main() {
int t;
//taking testcases
cin >> t;

while(t--){
int n, d;

//input n and d
cin >> n >> d;

int arr[n];

//inserting elements in the array
for(int i = 0; i < n; i++){
cin >> arr[i];
}
Solution ob;
//calling rotateArr() function
ob.rotateArr(arr, d,n);

//printing the elements of the array
for(int i =0;i<n;i++){
cout << arr[i] << " ";
}
cout << endl;
}
return 0;
} // } Driver Code Ends
50 changes: 50 additions & 0 deletions Character_arrays/shortestPath.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<iostream>
using namespace std;
int main(){
char direction[1000];
cout<<"Enter the direction First letter"<<endl;
cin.getline(direction,1000);
int x=0,y=0;
for(int i=0;direction[i]!='\0';i++){
switch(direction[i]){
case 'N':y++;break;
case 'S':y--;break;
case 'E':x++;break;
case 'W':x--;break;
}
}
cout<<"X and Y is "<<x<<" "<<y<<endl;
if(x>=0 and y>=0){
while(y--){
cout<<'N';
}
while(x--){
cout<<'E';
}
}
if(x<=0 and y>=0){
while(y--){
cout<<'N';
}
while(x++){
cout<<'W';
}
}
if(x<=0 and y<=0){
while(y++){
cout<<'S';
}
while(x++){
cout<<'W';
}
}
if(x>=0 and y<=0){
while(y++){
cout<<'S';
}
while(x--){
cout<<'E';
}
}
return 0;
}