• Welcome to Valhalla Legends Archive.
 

Programming help

Started by AC_Drkan, March 05, 2004, 10:18 AM

Previous topic - Next topic

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 [email protected]
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

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.
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!

AC_Drkan

Whoo!!!!

It works!

finished it at 12:30 on Satruday night.

Got an A

thanks for the help.

Dan
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

Grok

Quote from: Kp on March 05, 2004, 03:59 PM
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.

-1 for doing his homework.  :p

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.

Eli_1

#5
Quote from: AC_Drkan on March 05, 2004, 10:18 AM
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 [email protected]

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

AC_Drkan

srry a epeats 3 times and bad repeats 2 times so it returns "a" has repeated 3 times
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

AC_Drkan

Quote from: AC_Drkan on March 09, 2004, 10:33 AM
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 == 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 == 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 == 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");
}


although it only displays a it still works
Dan
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.

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.


           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
               {
               }


For example, could be written as

           /* 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);
           }


or better yet

           /* 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);


Clean, well documented code, is always a must.
asdf.

AC_Drkan

Yeah.

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

else
{
}

Thanks though

Dan
"The Arguments of Today Result in the Wars of Tomorrow" - Quote By Muah.
<@Logan> I spent a minute looking at my own code by accident.
<@Logan> I was thinking "What the hell is this guy doing?"

<kow`> "There are 10 types of people in the world... those who understand binary and those who don't."
<SpaceRain> That's only 2 types of people, kow.
<SpaceRain> STUPID


<[TN]FBMachine> i got kicked out of barnes and noble once for moving all the bibles into the fiction section

God i love Bash.org.