|
|
|||||||
| Computers & Information Technologies « Everything related to computers and internet. » |
![]() |
|
|
Share | Thread Tools | Search this Thread |
|
|
#11 |
|
Last Online: 12-20-2021
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,121
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
|
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.
|
|
|
|
| The Following 2 Users Say Thank You to Tawa For This Useful Post: | nabilsaleh1992 (11-20-2010), ZC (11-16-2010) |
|
|
#12 |
|
Registered Member
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
|
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!!!! ![]() ![]() |
|
|
|
|
|
#13 |
|
Registered Member
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
|
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!!!! ![]() ![]() |
|
|
|
|
|
#14 |
|
Registered Member
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
|
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!!!! ![]() ![]() |
|
|
|
|
|
#15 |
|
Registered Member
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
|
not working toli3
__________________
Books all say different things while people flap their yellow wings trying to soar by being a whore of life!!!! ![]() ![]() |
|
|
|
|
|
#16 |
|
Last Online: 12-20-2021
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,121
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
|
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.
|
|
|
|
|
|
#17 | |
|
Registered Member
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
|
Quote:
dude im taking the same course and i have the same assignment, would it happen that we're in the same class? |
|
|
|
|
|
|
#18 |
|
Registered Member
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
|
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; Last edited by Adam; 12-25-2010 at 05:59 PM. |
|
|
|
|
|
#19 | |
|
Last Online: 12-20-2021
Join Date: Mar 2006
Posts: 6,245
Thanks: 2,121
Thanked 3,365 Times in 1,740 Posts
Groans: 29
Groaned at 44 Times in 35 Posts
|
Quote:
__________________
What we do in life, echoes in eternity.
|
|
|
|
|
| The Following User Says Thank You to Tawa For This Useful Post: | Adam (12-25-2010) |
|
|
#20 | |
|
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
|
Quote:
__________________
|
|
|
|
|
| The Following User Says Thank You to Google For This Useful Post: | Adam (12-28-2010) |
![]() |
|
| Tags |
| helpc |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|