Vcoderz Community
We create websites that have it all, beauty & brains
Lebanon Web Design & Development - Coddict
 

Go Back   Vcoderz Community > Computer Zone > Computers & Information Technologies

Notices

Computers & Information Technologies Everything related to computers and internet.

Reply
 
Share Thread Tools Search this Thread
Old 11-16-2010   #11
Tawa
 
Tawa's Avatar
 
Last Online: 06-12-2019
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,120
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
Default

This should work:
Code:
#include <iostream>
#include <string>
using namespace std;

int main() {
    char a[100];
    char b[100];
    int la, lb;
    bool isSubstring = false;

    cout << "Enter first line: ";
    cin.get(a, 100, '\n');

    cout << "Enter second line: ";
    cin.ignore();
    cin.get(b, 100, '\n');

    la = strlen(a);
    lb = strlen(b);

    for(int i = 0; i < lb-la+1; i++){
        for(int j = 0; j < la; j++){
            if(b[i+j] != a[j])
                break;
            if(j == la-1)
                isSubstring = true;
        }
        if(isSubstring)
            break;
    }
    if(isSubstring)
        cout << "Yeah Baby!" << endl;
    else
        cout << "No! No! No!" << endl;

    return 0;
}


__________________
What we do in life, echoes in eternity.
Tawa is offline   Reply With Quote
The Following 2 Users Say Thank You to Tawa For This Useful Post:
nabilsaleh1992 (11-20-2010), ZC (11-16-2010)
Old 11-16-2010   #12
ZC
Registered Member
 
ZC's Avatar
 
Last Online: 07-15-2013
Join Date: Aug 2006
Posts: 100
Thanks: 13
Thanked 24 Times in 24 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Default

I ran it bi 3a222id:P man thanx aloooooooooot:P i guess ur smarter than me:P i didnt even understand what u did:P
__________________
Books all say different things while people flap their yellow wings trying
to soar by being a whore of life!!!!




ZC is offline   Reply With Quote
Old 11-16-2010   #13
ZC
Registered Member
 
ZC's Avatar
 
Last Online: 07-15-2013
Join Date: Aug 2006
Posts: 100
Thanks: 13
Thanked 24 Times in 24 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Default

can u explain the algorithM :P?
__________________
Books all say different things while people flap their yellow wings trying
to soar by being a whore of life!!!!




ZC is offline   Reply With Quote
Old 11-16-2010   #14
ZC
Registered Member
 
ZC's Avatar
 
Last Online: 07-15-2013
Join Date: Aug 2006
Posts: 100
Thanks: 13
Thanked 24 Times in 24 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Default

BTW fio problem... awwal string 3tee TAWAKBIR
teneh string 3teee AKBIR bi illak no :P
__________________
Books all say different things while people flap their yellow wings trying
to soar by being a whore of life!!!!




ZC is offline   Reply With Quote
Old 11-16-2010   #15
ZC
Registered Member
 
ZC's Avatar
 
Last Online: 07-15-2013
Join Date: Aug 2006
Posts: 100
Thanks: 13
Thanked 24 Times in 24 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Default

not working toli3
__________________
Books all say different things while people flap their yellow wings trying
to soar by being a whore of life!!!!




ZC is offline   Reply With Quote
Old 11-16-2010   #16
Tawa
 
Tawa's Avatar
 
Last Online: 06-12-2019
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,120
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
Default

Quote:
Originally Posted by ZC View Post
not working toli3
As I read in your post where you explained the homework, the program has to check if the "FIRST" string is a substring for the "SECOND".

So, if you input AKBIR then TAWAKBIR, it'll work.

So I guess it's working.
__________________
What we do in life, echoes in eternity.
Tawa is offline   Reply With Quote
Old 11-20-2010   #17
nabilsaleh1992
Registered Member
 
nabilsaleh1992's Avatar
 
Last Online: 11-20-2010
Join Date: Nov 2010
Posts: 1
Thanks: 1
Thanked 0 Times in 0 Posts
Groans: 0
Groaned at 0 Times in 0 Posts
Default the opposite is true...

Quote:
Originally Posted by ZC View Post
ask the user to input a string.. and then input another string.. the program should check if the second is a substring of teh first
it's the opposite you have to check if the first is a substring of the second.

dude im taking the same course and i have the same assignment, would it happen that we're in the same class?
nabilsaleh1992 is offline   Reply With Quote
Old 12-25-2010   #18
Adam
Registered Member
 
Adam's Avatar
 
Last Online: 06-03-2013
Join Date: Feb 2008
Posts: 1,410
Thanks: 1,444
Thanked 1,235 Times in 689 Posts
Groans: 25
Groaned at 21 Times in 19 Posts
Default

Does anyone know if there is any advantage in performance when using recursive binary search rather than normal binary search?


EDIT: I also find this piece of code when reading about recursive binary search...
Code:
int nMid = (nMin + nMax) >> 1;
Does anyone knows what it means?

Last edited by Adam; 12-25-2010 at 05:59 PM.
Adam is offline   Reply With Quote
Old 12-25-2010   #19
Tawa
 
Tawa's Avatar
 
Last Online: 06-12-2019
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,120
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
Default

Quote:
Originally Posted by Adam View Post
EDIT: I also find this piece of code when reading about recursive binary search...
Code:
int nMid = (nMin + nMax) >> 1;
Does anyone knows what it means?
http://www-numi.fnal.gov/offline_sof...rib/shift.html
__________________
What we do in life, echoes in eternity.
Tawa is offline   Reply With Quote
The Following User Says Thank You to Tawa For This Useful Post:
Adam (12-25-2010)
Old 12-28-2010   #20
Google

 
Google's Avatar
 
Last Online: 05-30-2013
Join Date: Jan 2008
Posts: 1,788
Thanks: 10,018
Thanked 1,100 Times in 651 Posts
Groans: 1
Groaned at 6 Times in 6 Posts
Default

Quote:
Originally Posted by Adam View Post
Does anyone know if there is any advantage in performance when using recursive binary search rather than normal binary search?


EDIT: I also find this piece of code when reading about recursive binary search...
Code:
int nMid = (nMin + nMax) >> 1;
Does anyone knows what it means?
This is just a division by two.
__________________

Google is offline   Reply With Quote
The Following User Says Thank You to Google For This Useful Post:
Adam (12-28-2010)
Reply

  Vcoderz Community > Computer Zone > Computers & Information Technologies

Tags
helpc



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:36 PM.


Lebanon web design and development
Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Share