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
137 changes: 137 additions & 0 deletions Rohan Sharma_14CSE_Jarvis
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
Name: Rohan Sharma
Roll no.: 14BTCSERS046
Stream: CSE
Compiler: GNU GCC
IDE: Code Blocks
OS: Windows 8.1 Pro
*/

#include <iostream>
#include <fstream>
#include <stdlib.h> //for 'exit()'

using namespace std;

/*---------------
Global Variables
-----------------*/
int a[1024][1024];

/*----------------------------
Function Declaration
------------------------------*/
/*
This functions recursively fills the surroundings of a[i][j] (i,j are passed to the function)
Note: Surroundings are top, bottom, left, right
*/
void fill_recursively(int,int);

int main()
{
char c;
int i,j,row=0,col=0;
ifstream fin; //to create input stream
fin.open("input.txt",ios::in); //to connect 'input.txt' to input stream 'fin'
fin.seekg(0); //to bring file pointer to file beginning
if(!fin) //to prompt error message if input file is not present
{
cout<<"Please add the file 'input.txt' in the same directory!\n\n";
system("pause");
exit(0);
}
while(!fin.eof()) //to count number of rows & columns & store the matrix from file in the 2D array 'a'
{
fin.get(c);
if(isdigit(c))
{
a[row][col++]=c-48;
}
if(c=='\n')
{
row++;
col=0;
}
}
row++;
col--;
fin.close(); //to disconnect 'input.txt' from 'fin'
/*
To start filling from boundary of the 2D array
Note: Outside filled places become '2'
*/
for(i=0;i<row;i++)
for(j=0;j<col;j++)
{
if(i==0||i==row-1)
if(a[i][j]==1)
{
a[i][j]==2;
fill_recursively(i,j);
}
else if(j==0||j==col-1)
if(a[i][j]==1)
{
a[i][j]=2;
fill_recursively(i,j);
}
}
for(i=0;i<row;i++) //to convert remaining 1s to 0s
for(j=0;j<col;j++)
if(a[i][j]==1)
a[i][j]=0;
for(i=0;i<row;i++) //to convert 2s back to 1s
for(j=0;j<col;j++)
if(a[i][j]==2)
a[i][j]=1;
ofstream fout;
fout.open("output.txt",ios::out|ios::trunc);
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
fout<<a[i][j];
if(j!=col-1)
fout<<" ";
}
if(i!=row-1)
fout<<"\n";
}
fout.close();
cout<<"Done!\nCheck file 'output.txt'\n\n\n\n\n";
return 0;
}

void fill_recursively(int i,int j)
{
if(a[i][j-1]==1)
{
a[i][j-1]=2;
fill_recursively(i,j-1);
}
if(a[i-1][j]==1)
{
a[i-1][j]=2;
fill_recursively(i-1,j);
}
if(a[i][j+1]==1)
{
a[i][j+1]=2;
fill_recursively(i,j+1);
}
if(a[i+1][j]==1)
{
a[i+1][j]=2;
fill_recursively(i+1,j);
}
if(a[i+1][j]==1)
{
a[i+1][j]=2;
fill_recursively(i+1,j);
}
if(a[i+1][j]==1)
{
a[i+1][j]=2;
fill_recursively(i+1,j);
}
}
57 changes: 57 additions & 0 deletions mayank gupta 14cs hal9000
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*mayank gupta 14cs hal9000
os windows 8.1
compiler devc++*/

#include<stdio.h>
#include<conio.h>
int main()
{ int a[100],b[100],c,d,temp,temp2,sum=0;
printf("enter the length of vector a");
scanf("%d",&c);
for(int i=0;i<c;i++)
{ scanf("%d",&a[i]);//getting vector a
}
printf("enter the length of vector d");
scanf("%d",&d);
for(int i=0;i<d;i++)
{ scanf("%d",&b[i]);//getting vector b
}
if(d!=c)
{ if(d<c)
{ for(int i=d;i<c;i++)
b[i]=0;
d=c;}
else
{ for( int j=c;j<d;j++)
a[j]=0;
c=d;}
}
int e[d];
for(int i=c-2;i>=0;i--){
for(int j=0;j<=i;j++){
if(a[j]>a[j+1]){
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;//bubble sort a
}
}
}
for(int i=d-2;i>=0;i--){
for(int j=0;j<=i;j++){
if(b[j]>b[j+1]){
temp2=b[j];
b[j]=b[j+1];
b[j+1]=temp2;//bubble sort b
}
}
}
for( int i=0;i<d;i++)
{
e[i]=a[i]*b[d-i-1];//multiplying smallest element of one vector tho biggest of other
}
for(int i=0;i<d;i++)
{ sum=sum+e[i];//summing up the product
}
printf("min dot product is %d",sum);
getch();
}