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

  • SEARCH
  • Home
  • 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 9148001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:09:01+00:00 2026-06-17T11:09:01+00:00

He told me to put any words into this program and I can see

  • 0

He told me to put any words into this program and I can see one transform to the other, but I have no idea where to insert the words I want. I downloaded CodeBlocks because it looked like the best C++ runner according to Google but when I click run it just says I need two strings. Guessing that means words.

Can anyone look at this and tell me how to insert 2 words?

The Program:

#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>

using namespace std;

#define MIN(X,Y) ((X <= Y) ? X:Y)
#define MIN3(A,B,C) ((A <= MIN(B,C)) ? A : MIN(B,C))

class EDIST {
private:
  string _s1, _s2;
  int _edit_distance;

  enum backtrace_pointer { L, D, U };
  // L==left, D==diagonal, U==up.

  vector<vector<int> > dp_table;
  vector<vector<int> > backtrace;

public:
  EDIST(const char *a, const char *b) {
    _s1 = a;
    _s2 = b;
    _edit_distance = 0;
  }

  void run();

private:
  int edit_distance() const { return _edit_distance; }
  void dp_edit_distance();
  void print_dp_tables();
  void init_dp_tables();
  void print_solution();
};

void EDIST :: print_dp_tables()
{
  cout << "\nPrinting dynamic programming table\n";

  cout << "\t_";
  for ( int i=0; i < _s2.size(); i++ )
    cout << "\t" << _s2[i];
  cout << endl;

  for ( int i=0; i <= _s1.size(); i++ ) {
    if ( i ) cout << _s1[i-1];
    else cout << "_";

    for ( int j=0; j <= _s2.size(); j++ )
      cout << "\t" << dp_table[i][j];
    cout << endl;
  }

  cout << "\nPrinting backtrace table\n";

  cout << "\t_";
  for ( int i=0; i < _s2.size(); i++ )
    cout << "\t" << _s2[i];
  cout << endl;

  for ( int i=0; i <= _s1.size(); i++ ) {
    if ( i ) cout << _s1[i-1];
    else cout << "_";

    for ( int j=0; j <= _s2.size(); j++ ) {
      cout << "\t";
      if ( backtrace[i][j] == L ) cout << "L";
      else if ( backtrace[i][j] == D ) cout << "D";
      else cout << "U";
    }
    cout << endl;
  }
}

void EDIST :: init_dp_tables()
{
  for ( int i=0; i <= _s1.size(); i++ ) {
    vector <int> v;
    vector<int> b;

    for ( int j=0; j <= _s2.size(); j++ ) {
      int n=0, op=0;;

      if ( !i ) { n=j; op=L; }
      else if ( !j ) { n=i; op=U; }
      else { n=0; op=D; }

      v.push_back(n);
      b.push_back(op);
    }

    dp_table.push_back(v);
    backtrace.push_back(b);
  }

  for ( int i=0; i <= _s1.size(); i++ )
    dp_table[i][0] = i;

  for ( int j=0; j <= _s2.size(); j++ )
    dp_table[0][j] = j;
}

void EDIST :: dp_edit_distance()
{
  for ( int j=1; j <= _s2.size(); j++ ) {

    for ( int i=1; i <= _s1.size(); i++ ) {

      int a = dp_table[i-1][j]+1;
      int b = dp_table[i-1][j-1];
      int c = dp_table[i][j-1]+1;

      if ( _s1[i-1] != _s2[j-1] )
    b++;

      dp_table[i][j] = MIN3(a,b,c);

      if ( a == dp_table[i][j] ) backtrace[i][j] = U;
      else if ( b == dp_table[i][j] ) backtrace[i][j] = D;
      else backtrace[i][j] = L;
    }
  }
}

void EDIST :: print_solution()
{
  vector<string> string_sequence;
  string_sequence.push_back(_s2);

  int i = _s1.size();
  int j = _s2.size();

  while ( i || j ) {

    string s = string_sequence[string_sequence.size()-1];

    bool add_string=true;
    int new_i=i, new_j=j;

    if ( backtrace[i][j] == L ) {//LEFT :: insert
      new_j--;
      s.erase(j-1,1);
    }
    else if ( backtrace[i][j] == U ) {//UP : delete
      new_i--;
      string sub1 = (j >= 1 ? s.substr(0,j) : "");
      string sub2 = (j < s.size() ? s.substr(j) : "");
      s = sub1 + _s1[i-1] + sub2;
    }
    else {//DIAGONAL : replace OR no-operation
      new_i--;
      new_j--;
      if ( i && j && dp_table[i][j] != dp_table[new_i][new_j] )
    s.replace(j-1,1,_s1.substr(i-1,1));
      else
    add_string = false;
    }

    if ( add_string ) {
      string_sequence.push_back(s);
      _edit_distance++;
    }

    i = new_i;
    j = new_j;
  }

  cout << "\nEdit distance : " << edit_distance() << endl;

  if ( string_sequence.size() )
    cout << "\nPrinting mutations : \n";

  for ( int i=string_sequence.size()-1; i >= 0; i-- )
    cout << "\t" << string_sequence[i] << endl;

}

void EDIST :: run()
{
  cout << "\nFinding edit-distance between strings `";
  cout << _s1 << "' and `" << _s2 << "'" << endl;

  init_dp_tables();
  dp_edit_distance();
  print_dp_tables();
  print_solution();
}

int main(int argc, char *argv[])
{
  if ( argc != 3 ) {
    cerr << "Need 2 strings as input!\n" << endl;
    exit(1);
  }

  EDIST e(argv[1], argv[2]);
  e.run();

  return 0;
}
  • 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-17T11:09:02+00:00Added an answer on June 17, 2026 at 11:09 am

    This is a question about CodeBlocks rather than about C++, but a quick Google search reveals that you need to select the “Set program arguments” option under the “Project” menu.

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

Sidebar

Related Questions

Hi I have been told by my hosting provider to add this to my
Personally I can't stand region tags, but clearly they have wide spread appeal for
I'm learning Python, and I can easily create a server on localhost, but other
In some cocos2d-iphone documentation , I was told to put this // IMPORTANT: Call
Someone told me to do this in order to keep track of latest people
I was told that a function defined as static in one .c file is
I have been told I will be let go at the end of the
I was told that the optimal way to program in C++ is to use
This is an odd problem, so I have to provide a bit of background.
I have been told that to access a UITextField in the setup i have

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.