Valhalla Legends Forums Archive | C/C++ Programming | Programming help

AuthorMessageTime
AC_Drkan
hey wassup?

i need some help here's the problem:
you enter a substring ex. input: "blaaabadbadx" output: "maximum repeat: 3 for bad and 3 for a"

basically your enter a string and it prints out the maximum repeaded substring

please post if you have anything.

this is in c

if you know some algorythims <---- whatever how u spell it

please post them here

Dan
accname on bnet: ac_drkan
email wagnerdmo@aol.com
March 5, 2004, 4:18 PM
Kp
This seems like a fairly straightforward challenge, but the problem seems so useless that I suspect it to be a CS homework assignment. As such, pseudocode only:

Iterate over the string for characters. For each character, count how many times it recurs before a different character occurs. Repeat for pairs of characters, then for triplets, etc. until you've tried all sizes that actually fit within the string. Be forewarned this is a brute force approach, and will likely degrade pretty badly in the face of a large input sample.
March 5, 2004, 9:59 PM
AC_Drkan
Whoo!!!!

It works!

finished it at 12:30 on Satruday night.

Got an A

thanks for the help.

Dan
March 8, 2004, 4:15 PM
Grok
[quote author=Kp link=board=30;threadid=5613;start=0#msg47771 date=1078523974]
This seems like a fairly straightforward challenge, but the problem seems so useless that I suspect it to be a CS homework assignment. As such, pseudocode only:

Iterate over the string for characters. For each character, count how many times it recurs before a different character occurs. Repeat for pairs of characters, then for triplets, etc. until you've tried all sizes that actually fit within the string. Be forewarned this is a brute force approach, and will likely degrade pretty badly in the face of a large input sample.
[/quote]

-1 for doing his homework. :p
March 8, 2004, 4:21 PM
Adron
I thought it was some rather nice help actually. And if AC_Drkan can understand and implement a written text or pseudocode explanation of an algorithm, he does show some promise. I hope that's not just a sign of how low my expectations have dropped.
March 8, 2004, 5:48 PM
Eli_1
[quote author=AC_Drkan link=board=30;threadid=5613;start=0#msg47673 date=1078503489]
hey wassup?

i need some help here's the problem:
you enter a substring ex. input: "blaaabadbadx" output: "maximum repeat: 3 for bad and 3 for a"

basically your enter a string and it prints out the maximum repeaded substring

please post if you have anything.

this is in c

if you know some algorythims <---- whatever how u spell it

please post them here

Dan
accname on bnet: ac_drkan
email wagnerdmo@aol.com
[/quote]

Doesn't "bad" only repeat twice?

Also:
If the string was something like "aabdaaabdaaaa"
how many times would the a repeat?
1.) 1
2.) 2
3.) 3
4.) 4
5.) 8
6.) 9
March 8, 2004, 8:06 PM
AC_Drkan
srry a epeats 3 times and bad repeats 2 times so it returns "a" has repeated 3 times
March 9, 2004, 4:31 PM
AC_Drkan
[quote author=AC_Drkan link=board=30;threadid=5613;start=0#msg48543 date=1078849982]
Here is my old code that i had been using

#include <stdio.h>
#define max 50 /* Declare the max characters contained in a string */

int equal_strings (char s1[]) /* loop to test to see if there are
characters that er the same */
{
int i = 0, a = 0, answer = 0, count = 0;

while ( s1[count] != '\0')
++count;

printf ("Total characters: %i\n\n", count);

for ( i = 1; i <= count; i++) /* initial loop */
{
printf ("No Substring at location: %i\n", i);
if ( s1[i] == s1[i + 1] && s1[i + 1] == s1[i + 2]) /* if the first 2
intergers are exactly alike */
{
for ( a = 1;a <= count; a++) /* secondary loop if first if is
successfull */
{
if (s1[i] == s1[i + 1]) /* double check to make sure first 2
intergers are exactly alike */
{
++i;
printf ("Substring Found at location %i\n", i);
}
else
{
}
if (s1[i] == s1[i + 2]) /* are the first and the third
alike as well? */
{
++i;
printf ("Substring Found at location %i\n", i);
}
else
{
}
}
return(1); /* Return successfull! :P */
}
else
{
}
}

return(answer); /* return failure :( */
}

main()
{
char text1[max];
int equal_strings (char s1[]);
int answer2;

printf ("String to be Tested: ");
scanf ("%s", text1); /* enter a string to be tested */

answer2 = equal_strings(text1);

if (answer2 == 1) /* a substring was found */
printf ("Substring found in %s\n", text1);
else /* substring wasn't found */
printf ("No Substring Found\n");
}

[/quote]

although it only displays a it still works
Dan
March 9, 2004, 4:36 PM
Maddox
It could help clarify your code to other people if you used common tab/space conventions. Also, just because you have an if, doesn't mean you need an else.

[code]
if (s1[i] == s1[i + 1]) /* double check to make sure first 2
intergers are exactly alike */
{
++i;
printf ("Substring Found at location %i\n", i);
}
else
{
}
[/code]

For example, could be written as
[code]
/* double check to make sure first 2 intergers are exactly alike */
if (s1[i] == s1[i + 1])
{
++i;
printf ("Substring Found at location %i\n", i);
}
[/code]

or better yet
[code]
/* double check to make sure first 2 intergers are exactly alike */
if (s1[i] == s1[i + 1])
printf ("Substring Found at location %i\n", ++i);
[/code]

Clean, well documented code, is always a must.
March 10, 2004, 1:20 AM
AC_Drkan
Yeah.

sorta had to put the else loop in there.
so just put it with

else
{
}

Thanks though

Dan
March 11, 2004, 4:37 PM

Search