Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8435281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:52:20+00:00 2026-06-10T06:52:20+00:00

I’d greatly appreciate help with that algorithm/pseudo code. Basically I’m looking for words with

  • 0

I’d greatly appreciate help with that algorithm/pseudo code.

Basically I’m looking for words with a particular pattern (doesn’t matter what). I have a special function to determine it, which returns 1 if the word fulfills the requirements.
When it does, the second word after that should be omitted and not saved in the output.
I had no problem with that, when the “chosen” words are separated by one “not chosen” word.
The problem is – what to do when the “chosen” ones appear one after the other ?

I’ve prepared such a pseudo code to clarify the situation a bit. But unfortunately it doesn’t work for all the combinations of “chosen” and “not chosen”.

I introduced three counters/variables, helping me to discover the position I’m currently at.

Following pseudo code isn’t in logical order!

if (counter == 2 || in_a_row >= 3) {
    erase = 1;
    counter--;
    yes = 0;
    if (!chosen) 
        counter = 0;
}
if (chosen) {
    counter++;
    yes = 1;
    in_a_row++;
} else {
    if (yes = 1) /* yes - is used when the preceeding word is chosen and the next is not chosen, in order to keep track of the counter */
        counter++;
}
if (in_a_row == 5)
    in_a_row = 4; /* just to make sure that counter doesn't go too high */
if (erase == 1)
    /*erasing procedure*/

If You have a simpler idea, or see a mistake in that one, PLEASE help me.
Trying to work that out for 8 hours…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T06:52:22+00:00Added an answer on June 10, 2026 at 6:52 am

    Pardon me for not using pseudo-code, instead I used actual code. I’m hoping I now understand the problem well enough that my belief that it doesn’t seem very complicated, is accurate.

    # include <stdio.h>
    # include <ctype.h>
    # include <string.h>
    
    
    # define BUFF_SIZE       1024
    # define WORD_DELIM     " "
    # define MATCH_PATT     "barf"
    
    
    int main(  int ac ,  char *av[]  )
    {
        __u_char    false = ( 1 == 0 ) ;
        __u_char    true = ( 1 == 1 ) ;
    
        __u_char    match_1_back = false ;
        __u_char    match_2_back = false ;
    
        char        line_buff[  BUFF_SIZE  ] ;
        char        *buff_ptr ;
        char        *word_ptr ;
    
    
        while (  fgets( line_buff ,  BUFF_SIZE ,  stdin )  )
        {
            puts(  "\nInput line was:  "  ) ;
            puts(  line_buff  )  ;
    
            puts(  "Output line is:  "  ) ;
    
            buff_ptr = line_buff ;
    
            while (  ( word_ptr = strtok( buff_ptr ,  WORD_DELIM )  )  !=  NULL  )
            {
                buff_ptr = NULL ;
    
                if (  strcmp( word_ptr ,  MATCH_PATT  )  ==  0  )
                {
                    // Set these to what they should be for next iteration.
                    match_2_back = match_1_back ;
                    match_1_back = true ;
    
                    // Don't output matched token.
                }
                else
                {
                    // Don't output token if a token matched 2 tokens back.
                    if (  ! match_2_back  )
                        printf(  "%s " ,  word_ptr  ) ;
    
                    // Set these to what they should be for next iteration.
                    match_2_back = match_1_back ;
                    match_1_back = false ;
                }
            }
    
            printf(  "\n"  ) ;
        }
    }
    

    With this input:

    barf   barf  barf   healthy     feeling     better   barf  barf barf uh oh sick again
    barf   barf  healthy     feeling     better   barf  barf uh oh sick again
    barf   healthy     barf   feeling     better     barf   uh   barf   oh sick again
    barf   healthy     feeling     better   barf uh oh sick again
    

    I got this output:

    Input line was:  
    barf   barf  barf   healthy     feeling     better   barf  barf barf uh oh sick again
    
    Output line is:  
    better sick again
    
    
    Input line was:  
    barf   barf  healthy     feeling     better   barf  barf uh oh sick again
    
    Output line is:  
    better sick again
    
    
    Input line was:  
    barf   healthy     barf   feeling     better     barf   uh   barf   oh sick again
    
    Output line is:  
    healthy feeling uh oh again
    
    
    Input line was:  
    barf   healthy     feeling     better   barf uh oh sick again
    
    Output line is:  
    healthy better uh sick again
    

    I just used a simple comparison, not actual regular expressions. I only wanted to illustrate the algorithm. Does the output conform to the requirements?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.