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
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<iostream>
using namespace std;

int main()
{
int n,m,i,j;
cin>>n>>m;
int arr[n][m];
for(i=0;i<n;i++)
for(j=0;j<m;j++)
cin>>arr[i][j];
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<arr[i][j]<<" ";\
}
cout<<endl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#include <iostream>
using namespace std;


const int mr = 100, mc = 100;

int** input(int** mat, int n, int m)
{
mat = new int* [n];
for (int i = 0; i < n; i++)
{
int* arr = new int[m];
for (int j = 0; j < m; j++)
{
cin >> arr[j];
}
mat[i] = arr;
}
return mat;
}


int main(int argc, char** argv)
{
int d=0,m,n; //0-e 1-s 2-w 3-n
cin >> n >> m;
int** mat = input(mat, n, m);
int i=0,j=0;
while(1)
{
d= (d+mat[i][j] )%4;
if(d==0)
j++;
else if(d==1)
i++;
else if(d==2)
j--;
else if(d==3)
i--;
if(i<0)
{
i++;
break;
}
else if(j<0)
{
j++;
break;
}
else if(i==n)
{
i--;
break;
}
else if(j==m)
{
j--;
break;
}
}
cout<<i<<endl<<j;
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <iostream>
using namespace std;


int main()
{
int i=0,j=0,dir,row,curr,col;
cin>>row>>col;
int **arr = new int*[row];
for(i=0;i<row;i++){
arr[i]=new int[col];
for(j=0;j<col;j++)
cin>>arr[i][j];
}
dir = 0,i=0,j=0;
while(i<row && j<col){
if(dir%4==0){
if(j+1==col)
break;
dir += arr[i][++j];
}
else if(dir%4==1){
if(i+1==row)
break;
dir += arr[++i][j];
}
else if(dir%4==2){
if(j==0)
break;
dir += arr[i][--j];
}
else if(dir%4==3){
if(i==0)
break;
dir += arr[--i][j];
}
}
cout<<i<<endl<<j;
/*
if(i==row)
cout<<i-1<<endl<<j;
else
cout<<i<<endl<<j-1;
*/
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include<iostream>
using namespace std;

int main()
{
int n1,m1,n2,m2,i,j,k;
cin>>n1>>m1;
int a[n1][m1];
for(i=0;i<n1;i++)
for(j=0;j<m1;j++)
cin>>a[i][j];

cin>>n2>>m2;
int b[n2][m2];
for(i=0;i<n2;i++)
for(j=0;j<m2;j++)
cin>>b[i][j];

int c[n1][m2];
if(m1 != n2)
cout<<"Invalid input";
else
{
for(i=0;i<n1;i++)
{
for(j=0;j<m2;j++)
{
c[i][j]=0;
for(k=0;k<m1;k++){
c[i][j] += a[i][k]*b[k][j];
}
}
}

for(i=0;i<n1;i++)
{
for(j=0;j<m2;j++)
{
cout<<c[i][j]<<" ";
}
cout<<endl;
}
}


}
68 changes: 68 additions & 0 deletions IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/RingRotate.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include<iostream>
using namespace std;

void rotate(long int* arr2, int n,int k){
int i,j=n;
long int *temp = new long int[n];
if(k<0)
k+=n;
for(i=k-1;i>=0;i--)
temp[i] = arr2[--j];
j=0;
for(i=k;i<n;i++)
temp[i]=arr2[j++];
for(i=0;i<n;i++)
arr2[i] = temp[i];
// write your code here

}

int main()
{
int s,r,row,col,i,j;
cin>>row>>col;
long int **arr1 = new long int*[row];
for(i=0;i<row;i++){
arr1[i] = new long int[col];
for(j=0;j<col;j++)
cin>>arr1[i][j];
}
cin>>s;
cin>>r;
int nelements = 2*(row+col-2*(2*s-1));
r = r%nelements;
long int*arr2 = new long int[nelements];
int ind=0;
for(j=s-1;j<row-s;j++)
arr2[ind++] = arr1[j][s-1];
for(j=s-1;j<col-s;j++)
arr2[ind++] = arr1[row-s][j];
for(j=row-s;j>s-1;j--)
arr2[ind++] = arr1[j][col-s];
for(j=col-s;j>s-1;j--)
arr2[ind++] = arr1[s-1][j];

/*
for(i=0;i<nelements;i++)
cout<<arr2[i]<<" ";
*/

rotate(arr2,nelements,r);
ind = 0;

for(j=s-1;j<row-s;j++)
arr1[j][s-1] = arr2[ind++];
for(j=s-1;j<col-s;j++)
arr1[row-s][j] = arr2[ind++];
for(j=row-s;j>s-1;j--)
arr1[j][col-s] = arr2[ind++];
for(j=col-s;j>s-1;j--)
arr1[s-1][j] = arr2[ind++];

for(i=0;i<row;i++){
for(j=0;j<col;j++)
cout<<arr1[i][j]<<" ";
cout<<endl;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void rotate(int n, vector<vector<int>> &arr)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=n-1; j>=0;j--)
{
cout<<arr[j][i]<<" ";
}
cout<<endl;
}

}

int main()
{
int n;
cin >> n;
vector<vector<int>> arr(n, vector<int>(n));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
cin >> arr[i][j];
rotate(n, arr);
}
30 changes: 30 additions & 0 deletions IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Rotateby90.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <iostream>
using namespace std;


int main()
{
int n,i,i2,j;
cin>>n;
int **arr = new int*[n];
for(i=0;i<n;i++){
arr[i] = new int[n];
for(j=0;j<n;j++)
cin>>arr[i][j];
}
int **arr2 = new int*[n];
for(i=0;i<n;i++)
arr2[i] = new int[n];
i2 = -1;
for(i=n-1;i>=0;i--){
i2++;
for(j=0;j<n;j++)
arr2[j][i2] = arr[i][j];
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
cout<<arr2[i][j]<<" ";
}
cout<<endl;
}
}
42 changes: 42 additions & 0 deletions IOT/kishanpriya169_PiyaKishan_2024ec1096_2/2DArrays/Sadle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include <iostream>
using namespace std;

bool constraint(long int i){
if(i> -1000000000 && i< 1000000000)
return true;
return false;
}

int main()
{
int n,i,j;
cin >> n;
long int** arr = new long int*[n];
int* min = new int[n];
for(i = 0; i < n; i++) {
arr[i] = new long int[n];
for (j = 0; j < n; j++) {
cin >> arr[i][j];
if(constraint(arr[i][j])){
if (j == 0)
min[i] = arr[i][j];
else if (arr[i][j] < min[i])
min[i] = arr[i][j];
}
else{
cout<<"Invalid input";
return 0;
}
}
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
if(arr[j][i]>min[i])
break;
}
//cout<<j<<" "<<min[i]<<endl;
if(j==n-1)
cout<<min[i];
}
return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>
using namespace std;

void search(int **arr,int n, int row,int key){
int i;
for(i=0;i<n;i++){
if(arr[row][i]==key){
cout<<row<<endl<<i;
break;
}
}
if(i==n)
cout<<"Not Found";
}

int main()
{
int n, key,i,j;
cin >> n;
int **arr = new int*[n];
for(i=0;i<n;i++){
arr[i] = new int[n];
for(j=0;j<n;j++)
cin>>arr[i][j];
}
cin>>key;
i=0;
for(i=0;i<n;i++){
if(key>= arr[i][0] && key<=arr[i][n-1]){
search(arr,n,i,key);
break;
}
}
if(i==n)
cout<<"Not Found";
}
Loading