#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;
}
Monday, 26 September 2016
Tic Tac Toe
class GameState attr_accessor :current_player, :board, :moves, :rank def initialize(current_player, board) self.current_player = current_player self.board = board self.moves = [] end def rank @rank ||= final_state_rank || intermediate_state_rank end # this is only ever called when it's the AI's (the X player) turn def next_move moves.max{ |a, b| a.rank <=> b.rank } end def final_state_rank if final_state? return 0 if draw? winner == "X" ? 1 : -1 end end def final_state? winner || draw? end def draw? board.compact.size == 9 && winner.nil? end def intermediate_state_rank # recursion, baby ranks = moves.collect{ |game_state| game_state.rank } if current_player == 'X' ranks.max else ranks.min end end def winner @winner ||= [ # horizontal wins [0, 1, 2], [3, 4, 5], [6, 7, 8], # vertical wins [0, 3, 6], [1, 4, 7], [2, 5, 8], # diagonal wins [0, 4, 8], [6, 4, 2] ].collect { |positions| ( board[positions[0]] == board[positions[1]] && board[positions[1]] == board[positions[2]] && board[positions[0]] ) || nil }.compact.first end end class GameTree def generate initial_game_state = GameState.new('X', Array.new(9)) generate_moves(initial_game_state) initial_game_state end def generate_moves(game_state) next_player = (game_state.current_player == 'X' ? 'O' : 'X') game_state.board.each_with_index do |player_at_position, position| unless player_at_position next_board = game_state.board.dup next_board[position] = game_state.current_player next_game_state = GameState.new(next_player, next_board) game_state.moves << next_game_state generate_moves(next_game_state) end end end end class Game def initialize @game_state = @initial_game_state = GameTree.new.generate end def turn if @game_state.final_state? describe_final_game_state puts "Play again? y/n" answer = gets if answer.downcase.strip == 'y' @game_state = @initial_game_state turn else exit end end if @game_state.current_player == 'X' puts "\n===============" @game_state = @game_state.next_move puts "X's move:" render_board turn else get_human_move puts "The result of your move:" render_board puts "" turn end end def render_board output = "" 0.upto(8) do |position| output << " #{@game_state.board[position] || position} " case position % 3 when 0, 1 then output << "|" when 2 then output << "\n-----------\n" unless position == 8 end end puts output end def get_human_move puts "Enter square # to place your 'O' in:" position = gets move = @game_state.moves.find{ |game_state| game_state.board[position.to_i] == 'O' } if move @game_state = move else puts "That's not a valid move" get_human_move end end def describe_final_game_state if @game_state.draw? puts "It was a draw!" elsif @game_state.winner == 'X' puts "X won!" else puts "O won!" end end end Game.new.turn
//ubuntu
//save as : tic.rb
//to compile/run : ruby tic.rb
//source : http://www.flyingmachinestudios.com
Monday, 12 September 2016
pointer with error
struct list{
int n;
struct list *next;
};
typedef struct list node;
node *temp,*start,*n_node;
node* getnode();
void insrt_nod(node*);
void show();
node* getnode()
{
int n;
temp=(node*)malloc(sizeof(node));
temp->next="NULL";
printf("\n enter the data:");
scanf("%d",&n);
return (temp);
}
void insrt_nod(node* temp)
{
if(start=="NULL")
start->next=n_node;
else
{
temp=start;
while(temp->next!="NULL")
temp=temp->next;
temp->next=n_node;
}
}
void show()
{
temp=start;
while(temp->next!="NULL")
{
temp=temp->next;
printf("\n%d",temp->n);}
}
void main()
{
printf("\n enter:\n");
n_node=getnode();
insrt_nod(n_node);
show();
}
int n;
struct list *next;
};
typedef struct list node;
node *temp,*start,*n_node;
node* getnode();
void insrt_nod(node*);
void show();
node* getnode()
{
int n;
temp=(node*)malloc(sizeof(node));
temp->next="NULL";
printf("\n enter the data:");
scanf("%d",&n);
return (temp);
}
void insrt_nod(node* temp)
{
if(start=="NULL")
start->next=n_node;
else
{
temp=start;
while(temp->next!="NULL")
temp=temp->next;
temp->next=n_node;
}
}
void show()
{
temp=start;
while(temp->next!="NULL")
{
temp=temp->next;
printf("\n%d",temp->n);}
}
void main()
{
printf("\n enter:\n");
n_node=getnode();
insrt_nod(n_node);
show();
}
Monday, 13 June 2016
D S - I.pdf
just click on "Open this in new window", and then the pdf will open....then click on download button
Or simply copy/open the link and click download button...
https://drive.google.com/file/d/0B_dVT88kjhz7ZXYzQzVxN1YwMU0/view?usp=sharing
link of DS-I
Tuesday, 31 May 2016
Addition and Subtraction of Matrix
//Addition and Subtraction of Matrix..
#include<stdio.h>
main()
{
int a[10][10], b[10][10], s[10][10],sub[10][10];
int r,c,r1=0, c1=0, r2=0, c2=0;
printf("Enter row no. ");
scanf("%d",&r1);
printf("Enter column no. ");
scanf("%d",&c1);
printf("Enter the elements of first array");
for(r=0; r<r1; r++)
{
for(c=0; c<c1; c++)
{
scanf("%d",&a[r][c]);
}
}
printf("Enter row no. ");
scanf("%d",&r2);
printf("Enter column no. ");
scanf("%d",&c2);
if(r1==r2 && c1==c2)
{
printf("Enter the elements of second array");
for(r=0; r<r2; r++)
{
for(c=0; c<c2; c++)
{
scanf("%d",&b[r][c]);
}
}
//addition & subtraction
for(r=0; r<r1; r++)
{
for(c=0; c<c1; c++)
{
s[r][c] = a[r][c]+b[r][c];
sub[r][c]= a[r][c]-b[r][c];
}
}
printf("Additiom is\n");
for(r=0; r<r1; r++)
{
for(c=0; c<c1; c++)
{
printf("%d\t",s[r][c]);
}
printf("\n");
}
printf("\n\n");
printf("Subtraction is\n");
for(r=0; r<r1; r++)
{
for(c=0; c<c1; c++)
{
printf("%d\t",sub[r][c]);
}
printf("\n");
}
}
else
{
printf("Invalid matrix");
}
}
#include<stdio.h>
main()
{
int a[10][10], b[10][10], s[10][10],sub[10][10];
int r,c,r1=0, c1=0, r2=0, c2=0;
printf("Enter row no. ");
scanf("%d",&r1);
printf("Enter column no. ");
scanf("%d",&c1);
printf("Enter the elements of first array");
for(r=0; r<r1; r++)
{
for(c=0; c<c1; c++)
{
scanf("%d",&a[r][c]);
}
}
printf("Enter row no. ");
scanf("%d",&r2);
printf("Enter column no. ");
scanf("%d",&c2);
if(r1==r2 && c1==c2)
{
printf("Enter the elements of second array");
for(r=0; r<r2; r++)
{
for(c=0; c<c2; c++)
{
scanf("%d",&b[r][c]);
}
}
//addition & subtraction
for(r=0; r<r1; r++)
{
for(c=0; c<c1; c++)
{
s[r][c] = a[r][c]+b[r][c];
sub[r][c]= a[r][c]-b[r][c];
}
}
printf("Additiom is\n");
for(r=0; r<r1; r++)
{
for(c=0; c<c1; c++)
{
printf("%d\t",s[r][c]);
}
printf("\n");
}
printf("\n\n");
printf("Subtraction is\n");
for(r=0; r<r1; r++)
{
for(c=0; c<c1; c++)
{
printf("%d\t",sub[r][c]);
}
printf("\n");
}
}
else
{
printf("Invalid matrix");
}
}
Subscribe to:
Posts (Atom)