#include<iostream>
#include<fstream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main()
{
time_t now = time(0);
char *dt = ctime(&now);
cout<<"Today is : "<<dt<<endl;
}
Friday, 23 December 2016
DATE AND TIME IN C++
Tuesday, 6 December 2016
quick_sort.cpp
#include<iostream>
using namespace std;
struct job
{
char c;
int p;
int d;
};
int partition(job a[],int p,int r)
{
int x;
x=a[r].p;
int i=p-1;
for(int j=p; j<=r-1; j++)
{
if(a[j].p<=x)
{
i=i+1;
int t=a[i].p;
a[i].p=a[j].p;
a[j].p=t;
}
int t=a[i+1].p;
a[i+1].p=a[r].p;
a[r].p=t;
}
cout<<endl<<"i+1 = "<<i+1;
return i+1;
}
void quicksort(job a[],int p,int r)
{
for(int i=0; i<=r; i++)
cout<<a[i].p<<" <--->"<<endl;
int q=0;
if(p<r)
{
q=partition(a,p,r);
cout<<"*******************************";
quicksort(a,p,q-1);
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*";
quicksort(a,q+1,r);
cout<<"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!";
}
}
int main()
{
int n;
int x;
cout<<"Enter the no. of jobs : ";
cin>>n;
job j[n];
//int di[n]={0};
//cout<<"Enter the profits in decreasing order : \n";
cout<<"Enter job name : ";
for(int i=0; i<n; i++)
{
cin>>j[i].c;
}
cout<<"Enter profit : ";
for(int i=0; i<n; i++)
{
cin>>j[i].p;
}
cout<<"Enter Deadline : ";
for(int i=0; i<n; i++)
{
cin>>j[i].d;
}
cout<<"You Entered \n";
for(int i=0; i<n; i++)
{
cout<<j[i].c<<" ";
cout<<j[i].p<<" ";
cout<<j[i].d<<" ";
cout<<endl;
}
quicksort(j,0,n-1);
cout<<"Sorted profit is : "<<endl;
for(int i=0; i<n; i++)
{
cout<<j[i].p;
}
cout<<endl<<"You Entered \n";
for(int i=0; i<n; i++)
{
cout<<j[i].c<<" ";
cout<<j[i].p<<" ";
cout<<j[i].d<<" ";
cout<<endl;
}
}
Sunday, 4 December 2016
job sech
#include<iostream>
using namespace std;
struct job
{
char c;
int p;
int d;
};
int main()
{
int dl;
int n;
int x;
//cout<<"Enter the Deadlne : ";
//cin>>dl;
cout<<"Enter the no. of jobs : ";
cin>>n;
job j[n];
int di[6]={0};
cout<<"Enter the profits in decreasing order : \n";
cout<<"Enter job name : ";
for(int i=1; i<=n; i++)
{
cin>>j[i].c;
}
cout<<"Enter profit : ";
for(int i=1; i<=n; i++)
{
cin>>j[i].p;
}
cout<<"Enter Deadline : ";
for(int i=1; i<=n; i++)
{
cin>>j[i].d;
}
cout<<"You Entered \n";
for(int i=1; i<=n; i++)
{
cout<<j[i].c<<" ";
cout<<j[i].p<<" ";
cout<<j[i].d<<" ";
cout<<endl;
}
//x=j[1].d;
for(int i=1; i<=n; i++)
{
x=j[i].d;
if(di[x] == 0)
{
di[x]=j[i].p;
}
else
{
int t=j[i].d;
while(di[t]!=0)
{
t--;
}
if(t>=1)
di[t]=j[i].p;
}
}
int sum=0;
for(int i=1; i<=n; i++)
{
cout<<di[i]<<" ";
sum = sum+di[i];
}
cout<<"!!! Total Profit is "<<sum;
}
Subscribe to:
Posts (Atom)