shankhs 0 Junior Poster in Training

Hi frnds,
I am a newbie to python ( I am learning it for 1 month now on win platform) .I came across these cool functions of python like os.path.isdir("\\\\blah\\") but since "blah" is password protected I am always getting false as return!!!!

Can anyone please tell me how to supply username and password so that I can access "blah".

Thank You

shankhs 0 Junior Poster in Training

I have started learning wxWidgets... and its kinda fun :)

shankhs 0 Junior Poster in Training

Next step ? Pick one ;

1) Learn more about C++, for there is practically no limit.
2) Learn more about algorithms and data structures
3) Learn about design patterns
4) Pick a similar language, java , C# ?
5) Pick different language like haskel, php?
6) Go buy stocks?
7) Find a hot girl?

I would like to go for 7 :) though i think its gonna be harder than learning Java...
Any comments(or help or recommendations will be highly appreciated ;P)?

shankhs 0 Junior Poster in Training

>There are a lot of programs that do not require GUI, console, or human interaction.
Sadly, there's a misconception (especially among beginners) that GUI programming is the "next step" toward being a real programmer. :icon_rolleyes:

I know GUI programs wont make me a "real" programmer....(That's one thing every real programmer teaches in a very hard way).
I am trying to explore various stuffs that I can do alongwith implementing algos.
I don't think more knowledge is a bad thing.
Anyways guys I discovered this cool app http://www.autoitscript.com/autoit3/index.shtml which automates a lot of things ( sadly only for windows).
If you know other softwares that do similar stuffs please tell us...please reply to this thread.

shankhs 0 Junior Poster in Training

Why?

Because at first we can declare something like:
int *a;

and then

scanf("%d",&n);
a=malloc(sizeof(int[n]));

then we wont require value of 'n' prior to the array declaration.

shankhs 0 Junior Poster in Training

Hi,
I am using C/C++ for 4 years now,solving algorithmic problems only.
I see many softwares that do fancy stuffs like windows softwares which automate the installation process , move the mouse automatically and buttons are clicked.
Please can anyone tell me what programming language is used in such cases?
Any info will be helpful.


thanx

shankhs 0 Junior Poster in Training

Thanx Narue and BevoX
Ya Narue you are correct I do want to be well-rounded.

shankhs 0 Junior Poster in Training

I dont know whether this is the right place to post this question but I think you guys have huge experiences so...
I had a course on both algorithms and software engineering , and now I feel that I can devote my time to only one of these( as these both topics are vast and very time consuming) .I know that algos are necessary to develop efficient and effective softwares but I just couldnt decide what should be my priority learning algorithms( solving problems from acm ) or create new softwares( learn different patterns and different tools).
I hope you will help me.
Thankyou.

shankhs 0 Junior Poster in Training

Thanx for the help.
Actually I have learned lists , stacks and queues.I have to learn trees and graphs and searching theory,I am using Cormen.Do I also need to study Red-Black Trees and AVL trees to understand suffix trees??

shankhs 0 Junior Poster in Training

Can anybody please tell me what are the pre-requisites to understand the suffix trees.
I am learning suffix tree from this:
http://www.allisons.org/ll/AlgDS/Tree/Suffix/
I am not very good at algorithms and I couldnt understand how suffix trees are made.
Please help me!

shankhs 0 Junior Poster in Training

Thanx for all the help. I have "Beginning C# 2008" and I have already started reading it.

shankhs 0 Junior Poster in Training

I have just started learning C#....
But I am not getting any good place or book to learn I know C/C++.
I would also like to learn .NET(I have no idea what it is).
Can you suggest some book or place from where I can start with?

shankhs 0 Junior Poster in Training

Or...

bool check(const std::string str, const std::string ori)
{
   return ((stricmp(str.c_str(),ori.c_str())==0)?true:false);
}

std::string palindrome(const std::string str)
{
   int size=str.length();
   std::string reverse_str;
   for(int i=((size)-1);i>=0;i--)
      reverse_str.push_back(str[i]);
   if(check(reverse_str,str))
      return reverse_str;
   return "it's not a palindrome";
}

int main()
{
   std::string m_str=palindrome("dlrow olleh hello world");
   std::cout<<m_str.c_str();
   std::cin.get();
   return 0;   
}

My problem is to find longest substring that is a palindrome not to check whether the string is palindrome or not.

shankhs 0 Junior Poster in Training

From the link you posted:


That shouldn't be much difficult to implement, and

Give it a try and then post your efforts in case you need help.

If you see the code in my first post I have done exactly that .the first loop determines the length of the substring to be checked and the second loop checks for each position in the array to get the substring of the specified length.
But this is giving me TLE..I need to optimize it.

shankhs 0 Junior Poster in Training

Can i get another algorithm???

shankhs 0 Junior Poster in Training

Hey guys Please help me...
I am new to algorithms if there is an algorithm to find longest palindrome in a string just give me a link thats enough I will try my best to understand that.
Thankyou.

shankhs 0 Junior Poster in Training

I am searching an efficient algorithm to find all the palindromes in a string(actually I have to find the largest palindrome in a string)..
Here is my code

string palindrome(string str)
{
	
	int n=sz(str);
	
	for(int l=n-1;l>=0;l--)//Palindrome can be of any size.
	{
		for(int i=0;i<n-l+1;i++)
		{
			int j=i+l-1;
			
			string str2=str.substr(i,j-i+1);
			
			if(check_pal(str2)) return str2;//check_pal simply checks whether //the string is palindrome or not.
		}
	}
	
	string t1="";
	return t1;
}

This is an O(n^3)(since check_pal requires another loop),I searched and got this:
http://johanjeuring.blogspot.com/2007/08/finding-palindromes.html

But I cant understand a word of it What is his algo? How is it linear?
Please help me...

shankhs 0 Junior Poster in Training

I was a bit confused thanx for your quick reply
Final code

#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;

int main()
{
    ifstream fin;
    string temp="";
    string str;
    getline(cin,str);
    cout<<str<<endl;
    for(int i=0;i<str.size();i++)
    {
            if(str[i]=='\\')
                            temp+="\\";
            temp+=str[i];
            //cout<<str[i]<<endl;
            }
            
            str=temp;//cout<<temp<<" "<<str<<endl;
    fin.open(str.c_str(),ios::in);
    if(!fin)
            cout<<"Cant";
    else
        cout<<"can";
        
    system("pause");
    return 0;
}

Problem solved.

shankhs 0 Junior Poster in Training

I was trying to write a program that takes an input from a file which is located in Desktop not the default directory where the program is saved

#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;

int main()
{
    ifstream fin;
    string str="C:\Documents and Settings\shankhs\Desktop\ccs\Assignment CCS.txt",temp="";
    cout<<str<<endl;
    for(int i=0;i<str.size();i++)
    {
            if(str[i]=='\\')
                            temp+="\\";
            temp+=str[i];
            cout<<str[i]<<endl;
            }
            cout<<temp<<" "<<str<<endl;
    fin.open((char *)&str,ios::in);
    if(!fin)
            cout<<"Cant";
    else
        cout<<"can";
        
    system("pause");
    return 0;
}

The escape character '\' is causing a lot of trouble as '\' is not taken by the variable since its a special character (I have taken input in str but actually I have to take it from user who will just copy and paste the path and filename) how to get out of this mess????
PLZ HELP!

shankhs 0 Junior Poster in Training
Let [B]he/she[/B] gets the feel of new language (that's C)...

I am he.Thanks for pointing out the errors.Am I declaring the function and calling it correctly?

shankhs 0 Junior Poster in Training
100 5
5 20
9 40
3 10
8 80
6 30

The first line first integer is the amount of milk that I want per day and The second, is the number of farmers that I may buy from. The next lines contain the cost of milk and the max amount of milk that farmer can supply.
I am making a struct whilch contains cost and amt(amount that a farmer can supply) , I want to minimise the cost to buy the given amount of milk .I am sorting this structure as

struct str
{
	int cost;
	int amt;
};
typedef struct str tc;
tc * sort(tc cases[],int n)
{
	for(int j=1;j<n;j++)
	{
		int key=cases[j].cost;
		int k=cases[j].amt;
		i=j-1;
		while(i>=0&&key<=cases[i].cost)
		{
			if(key<cases[i].cost)
			{
				cases[i+1].cost=cases[i].cost;
				cases[i+1].amt=cases[i].amt;
			}
			else if(key==classes[i].cost)
			{
				if(cases[i].amt>k)
				{
				cases[i+1].cost=cases[i].cost;
				cases[i+1].amt=cases[i].amt;
				}
			}
			i=i-1;
		}
		cases[i+1].cost=key
		cases[i+1].amt=k;
	}
	return cases;
}

The sorting(insertion sort) is done wrt the first field if the first field is equal in two cases the second field decides which one will come first.
My main problem is in declaration and calling,actually I am learning to handle pointers so I am not very good at it I am calling the above method as

tc cases[no_far];//no_far==no of farmers
	for(int i=0;i<no_far;i++)
	{
		cin>>cases[i].cost>>cases[i].amt;
	}
	cases=sort(cases,no_far);

Please help,

shankhs 0 Junior Poster in Training

I dont want to use qsort.

shankhs 0 Junior Poster in Training

I am trying to solve a typical 0/1 knapsack problem (using greedy algorithm). In this problem I have to sort a structure consisting of 2 ints (one that contains the value and their corresponding amount I have to minimize the value to get `n' amounts so i need to sort) I am not able to do so.Please help me out.
Please tell me if there exist any better coding method to solve greedy knapsack problem.

shankhs 0 Junior Poster in Training

Thanx Tilir I found the bug at last
It was in :

double distance(int a[],int b[])
{
    double d1=b[0]-a[0];
    double d2=b[1]-a[1];
    //printf("%f\n",sqrt(d1*d1+d2*d2));
    return (abs)(sqrt(d1*d1+d2*d2));
}

I removed "abs" from

return (abs)(sqrt(d1*d1+d2*d2));

and whoa!!! it started working I think the "abs" function has some problem let me study about "abs" function first.....

shankhs 0 Junior Poster in Training

Hi guys!
I have started learning geometry and wrote a code to calculate the distance between a line(or a segment) and a point.
Here is my code:

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int dot_pdt(int a[],int b[],int c[])
{
    int ab[2],bc[2];
    
    ab[0]=b[0]-a[0];
    ab[1]=b[1]-a[1];
    
    bc[0]=c[0]-b[0];
    bc[1]=c[1]-b[1];
   // printf("%d\n",(ab[0]*bc[0]+ab[1]*bc[1]));
    return (ab[0]*bc[0]+ab[1]*bc[1]);
}

int cross_pdt(int a[],int b[],int c[])
{
    int ab[2],ac[2];
    
    ab[0]=b[0]-a[0];
    ab[1]=b[1]-a[1];
    
    ac[0]=c[0]-a[0];
    ac[1]=c[1]-a[1];
    //printf("%d\n",(abs)(ab[0]*ac[1]-ab[1]*ac[0]));
    return (abs)(ab[0]*ac[1]-ab[1]*ac[0]);
}

double distance(int a[],int b[])
{
    int d1=b[0]-a[0];
    int d2=b[1]-a[1];
    //printf("%f\n",sqrt(d1*d1+d2*d2));
    return (abs)(sqrt(d1*d1+d2*d2));
}

double linepointdist(int a[],int b[],int c[],int isSegment)
{
    double dist=cross_pdt(a,b,c)/distance(a,b);
    printf("%f\n",dist);
    int d1,d2;
    //If the problem is not a line but a segment.
    if(isSegment)
    {
        d1=dot_pdt(a,b,c);
        if(d1>0){printf("1\n"); return distance(b,c);}
        
        d2=dot_pdt(b,a,c);
        if(d2>0){printf("2\n"); return distance(a,c);}
    }
    return dist;
}

int main()
{
    int a[2],b[2],c[2];
    
    scanf("%d %d %d %d %d %d",&a[0],&a[1],&b[0],&b[1],&c[0],&c[1]);
    
	printf("%f",linepointdist(a,b,c,1));	
    
	return 0;
}

the problem is what I get is always an integer not a float value.
I have a input of

0 0 1 2 0 3

I get

1.000000

instead of

1.500000

The bug might be silly but its killing me.:'(
PLZ HELP.

shankhs 0 Junior Poster in Training

Pretty harsh reply by AncientDragon but a very good one...
Just google it and you will find methods and even the source code.

shankhs 0 Junior Poster in Training

thanx iamthwee the link was really helpful.

shankhs 0 Junior Poster in Training

I am trying to implement edit string algorithm given in:

http://en.wikipedia.org/wiki/Levenshtein_distance

in C and I am repeatedly getting "segmentation Fault" I dont understand why......:(

Here is my code

#include<stdio.h>
#include<string.h>

int minimum(int a,int b,int c)
{
    int min;
    
    if(a<b)
    {
        if(a<c) min=a;
        else min=c;
    }
    else
    {
        if(c<b) min=c;
        else min=b;
    }
    
    return min;
}

int edit_string(char *p,char *q)
{
    int len_p=strlen(p),len_q=strlen(q);
    
    int cost_matrix[100][100];
    int i,j;
    int cost;
    
    for(i=0;i<100;i++)
        for(j=0;j<100;j++) cost_matrix[i][j]=0;
        
    for(j=0;j<=len_q;j++)
        cost_matrix[0][j]=j;
        
    for(i=0;i<=len_p;i++)
        cost_matrix[i][0]=i;
        
    for(i=1;i<=len_p;i++)
    {
        for(j=1;j<=len_q;j++)
        {
            if(p[i-1]==q[j-1]) cost=0;
            else    cost=1;            
            
            cost_matrix[i][j]=minimum(cost_matrix[i-1][j],cost_matrix[i][j-1],cost_matrix[i-1][j-1]+cost);
            
        }
    }
    return cost_matrix[len_p][len_q];
}

int main()
{
    char *str1,*str2;
    int ans;
    
    gets(str1);
    gets(str2);
    
    ans=edit_string(str1,str2);
    
    printf("\n%d",ans);
        
    return 0;
}

I think the code is self explanatory....
Thanx for any suggestion....

shankhs 0 Junior Poster in Training

All strings should finish with a '\0', known as a NULL Terminator. Without it, Problems may appear

Also it is used in many standard C++ functions like strlen.

You could rewrite the strlen function like this:

size_t strlen(const char *str) {
	size_t len = 0;
	while (*str++) len++;
	// Terminates when the NULL character is reached
	/*
	Same as:
	 while (*str++ != 0) len++;
	*/
	return len;
}

When you assign a string like this:

char str[] = "Hello";

The NULL Terminator is automaticly placed at the end.

hey just give a look on vmanes idea on c++ strings in:
http://www.daniweb.com/forums/thread124696.html
it said:

Two points:
C++ string is not required to have NULL terminator ('\0'), but you will find it present under many compilers. One should not use this as a limit on the extent of the string, use the .length() or .size( ) methods.

C-style strings end with '\0', not '\n'. The newline is a character that may be embedded within a string.

now I am confused whether it is good to use '\0' or string.size() for the check condition in recursion!!!

shankhs 0 Junior Poster in Training

thanx salem its a good link
but i wanted something that could teach me how to make graphs in c++ or C,
i know there are lots of books but some follow adjacncy matrix some list but i want to know all the ways to construct a graph and i decide which one to follow....
Is that possible?
any book or link?
That would be very helpful i am really having a hard time to figure out how to make graphs....:(

shankhs 0 Junior Poster in Training

hey am i wrong with the c++ version of the code :

#include<iostream>

using namespace std;
bool rec(string a,string b,int i)
{
	if(a[i]!='\0'||b[i]!='\0')
	{
		if(a[i]!=b[i])
			return false;
		else return rec(a,b,i+1);
	}
	else return true;

}
int main()
{
	string str1="shankhs1";
	string str2="shankhs";
	cout<<rec(str1,str2,0);
	return 0;
}

is it good to end up string with '\0' or it should be '\n'???

shankhs 0 Junior Poster in Training

hey guys do u know any good on line tutorial of graphs?
ya i know there are many but i want the one which has source code to play around......
PLUS a detail description....
Thanx

shankhs 0 Junior Poster in Training

I want to recursively check if two strings are equal, not in size, but character by character. I am unallowed to use loops and the == operator.

I tried to use two parallel arrays, but when testing my function I got undesired results.

Here's what I came up with:

int main()
{
cout << "Checking equivalence of two strings using recursion." << endl << endl;

	cout << "For two strings of size 2: ";
	char ArrayA[ 100 ] = { 't', 'a', 'r' };
	int SizeA = 2;
	char ArrayB[ 100 ] = { 't', 'a', 'r' };
	int SizeB = 2;
	cout << String1EqualString2( ArrayA, SizeA, ArrayB, SizeB );

	HoldScreen();

}

bool String1EqualString2( char ArrayA[], int SizeA, char ArrayB[], int SizeB )
{
	
	if ( SizeA <= 1 && SizeB <= 1 )
		return true;
	else if ( ArrayA[0] != ArrayA[1] && ArrayB[0] != ArrayB[1] )
		return false;

	return String1EqualString2( ArrayA+1, SizeA-1 , ArrayB+1, SizeB-1 );

}

hey could you plz make your prob a bit more clear?????

shankhs 0 Junior Poster in Training

hey vijayan gr8 link thanx

shankhs 0 Junior Poster in Training

so tesuji can you suggest an algorithm better than FFT for getting large numbers(of the order of 10 power 30 or more)?????????

shankhs 0 Junior Poster in Training

thanx i implemented getline wrong so i was getting wrong answer thak you very much

shankhs 0 Junior Poster in Training

hey I want to input a string that contain spaces such as "My name is Shankhs";
i initialized a string str;
then cin>>str;
but str is not taking words after spaces as if spaces are acting as a delimiter...
i tried gets,getline but they does not seem to work for string!!!
So guys what should I do to make string take words after spaces???
(P.S. I have to work with string no char [] or char * please)
Thanx for your concern

shankhs 0 Junior Poster in Training

hi compton11 thanx for the link look i have 2 reasons not to use next_permutation:
1.I am learnung recursion (dat btw i am doing it by myself no instructor)
2.next_permutation gives permutation of characters in a set not from different sets....
So only technique left is RECURSION.
Ok if u havent understood the question the problem is to permute the characters taking from different sets.....
LIKE if you have to take sets 2512:
then there will be 81 strings of length 4 and characters for every string is taken in order {"char from2","char from 5","char from1","char from2",}(this is one string).....
So i think i am now clear?????
Thanx for ur help

shankhs 0 Junior Poster in Training

hi compton11 thanx for the link look i have 2 reasons not to use next_permutation:
1.I am learnung recursion (dat btw i am doing it by myself no instructor)
2.next_permutation gives permutation of characters in a set not from different sets....
So only technique left is RECURSION.
Thanx for ur help

shankhs 0 Junior Poster in Training

tesuji how large you want your number to be???
However large it is it is always generated by computer try multiplying two largest numbers known to u and I think you will end up with getting a longer number!!!!!!
(you can use FFT algorithm to multiply extremely large numbers)

shankhs 0 Junior Poster in Training

I have a problem in printing out the permutation of various characters grouped together like
string 0 has"ABC"
1: "DEF"
2:"GHI"
3:"JKL"
4."MNO"
5."PRS"
6."TUV"
7."WXY"

now i have to print all the permutation of the characters to form 1 letter to 12 letter words
lets say i have 2512
then my possible permutation will be 81 strings like GPDG GPDH GPDI GPEG GPEH GPEI GPFG GPFH GPFI GRDG GRDH GRDI ........

and the number can be even 25123 or longer
so one of the possible approach is recursion:
so I tried:

char rec(string in[],vector<int> brand,int i,int j,int l)
{	
	if(j==l){
		j=0;
		name+=rec(in,brand,++i,++j,l);
		--l;
		return in[brand[i]][j];
	}
	if(l==-1)
	{
		l=2;j=0;i+=1;
	}
	name+=rec(in,brand,i,++j,l);
}

PLZ help me as I am learning recursion by myself and its a very hard topic.......

shankhs 0 Junior Poster in Training

thanx vernondozier

shankhs 0 Junior Poster in Training

ok i know it does but i was practicing recursion and i am struck at this problem the output is:
sshknahs
Why 2 s??????
PLZ help!

shankhs 0 Junior Poster in Training

ok I replaced "while" with "if" and got output as:
sshknahs
????????

shankhs 0 Junior Poster in Training

can anybody suggest me whats wrong with the code??

#include<iostream>
#include<string>

using namespace std;

void rev_str(string str,int n)
{
	while(str[n]!='\0')
		rev_str(str,++n);
		
	cout<<str[n-1];
}
int main()
{
	string str="shankhs";
	rev_str(str,0);
	return 0;
}

thanks

shankhs 0 Junior Poster in Training

so far so gud thanx the program ran....
but I have one question....
pointer to a variable means a thing which points to the variable i.e.it stores the address of the variable...right?
What does pointer to a function imply?
a variable which is pointer to a function stores the address of the function????:-O
but the function is made at run time...correct me if I am wrong?:$
:?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?: :?:

shankhs 0 Junior Poster in Training

btw thanx for your fast reply.

shankhs 0 Junior Poster in Training

hey I tried this one also:

#include<iostream>
#include<fstream>
#include<vector>

using namespace std;
int i=5,j=8;
int add()
{
	int c=i+j;
	cout<<c;
	return c;
}
int sub()
{	
	int c=j-i;
	cout<<c;
	return c;
}
int try(int (*fn)() )
{
	if(add()>10)
           try(sub);
}
int main()
{
	try(add);
	return 0;
}

but i got following compile errors:(bekar.cpp is filename)

bekar.cpp:19: error: expected unqualified-id before "try"
bekar.cpp: In function `int main()':
bekar.cpp:26: error: expected `{' before '(' token
bekar.cpp:26: error: expected `catch' before '(' token
bekar.cpp:26: error: `add' is not a type
bekar.cpp:26: error: invalid catch parameter
bekar.cpp:26: error: expected `{' before ';' token
bekar.cpp:28:2: warning: no newline at end of file

What is wrong with the compiler????:S

shankhs 0 Junior Poster in Training

Hi all,
Do u have any idea that whether I can pass any function as a parameter to another function?
like:

#include<iostream>
#include<fstream>
#include<vector>

using namespace std;
int i=5,j=8;
int add()
{
	int c=i+j;
	return c;
}
int sub()
{	
	int c=j-i;
	return c;
}
int try(int *add)
{
	if(add()>10)
           try(sub);
}
int main()
{
	cout<<try;
}

What do you think is this correct (it gave lots of compiling error)...If not is there any other method to do such thing?:-/

shankhs 0 Junior Poster in Training

I am using visual studio 2005 and I dont know how to see the sample codes........
Thanx for the help.