Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. PLEASE HELP ME CONVERT C++ TO PYTHON

PLEASE HELP ME CONVERT C++ TO PYTHON

Scheduled Pinned Locked Moved C#
c++pythonhelp
6 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ege yay
    wrote on last edited by
    #1

    string laceStrings(const string& s1, const string& s2)
    {
    if (s1.empty())
    return s2;
    if (s2.empty())
    return s1;

    string laced;
    laced.resize(s1.size() + s2.size());
    
    int i = 0, pos = 0;
    int size = std::min(s1.size(), s2.size());
    
    // interlace common lengths substrings
    for ( ; i < size; ++i)
    {
        laced\[pos++\] = s1\[i\];
        laced\[pos++\] = s2\[i\];
    }
    
    // append the remainder of longer string
    if (s1.size() >= s2.size())
        for ( ; i < s1.size(); ++i)
            laced\[pos++\] = s1\[i\];
    else
        for ( ; i < s2.size(); ++i)
            laced\[pos++\] = s2\[i\];
    
    return laced;
    

    }

    D P A T 4 Replies Last reply
    0
    • E ege yay

      string laceStrings(const string& s1, const string& s2)
      {
      if (s1.empty())
      return s2;
      if (s2.empty())
      return s1;

      string laced;
      laced.resize(s1.size() + s2.size());
      
      int i = 0, pos = 0;
      int size = std::min(s1.size(), s2.size());
      
      // interlace common lengths substrings
      for ( ; i < size; ++i)
      {
          laced\[pos++\] = s1\[i\];
          laced\[pos++\] = s2\[i\];
      }
      
      // append the remainder of longer string
      if (s1.size() >= s2.size())
          for ( ; i < s1.size(); ++i)
              laced\[pos++\] = s1\[i\];
      else
          for ( ; i < s2.size(); ++i)
              laced\[pos++\] = s2\[i\];
      
      return laced;
      

      }

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Sorry, but that's not how it works. We're not here to do your work for you. We'll help if you've got a specific question or problem.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      B 1 Reply Last reply
      0
      • E ege yay

        string laceStrings(const string& s1, const string& s2)
        {
        if (s1.empty())
        return s2;
        if (s2.empty())
        return s1;

        string laced;
        laced.resize(s1.size() + s2.size());
        
        int i = 0, pos = 0;
        int size = std::min(s1.size(), s2.size());
        
        // interlace common lengths substrings
        for ( ; i < size; ++i)
        {
            laced\[pos++\] = s1\[i\];
            laced\[pos++\] = s2\[i\];
        }
        
        // append the remainder of longer string
        if (s1.size() >= s2.size())
            for ( ; i < s1.size(); ++i)
                laced\[pos++\] = s1\[i\];
        else
            for ( ; i < s2.size(); ++i)
                laced\[pos++\] = s2\[i\];
        
        return laced;
        

        }

        P Offline
        P Offline
        Pete OHanlon
        wrote on last edited by
        #3

        Adding to Dave's comment, you are asking a question about C++ and Python in a C# forum. That's not very clever.

        1 Reply Last reply
        0
        • E ege yay

          string laceStrings(const string& s1, const string& s2)
          {
          if (s1.empty())
          return s2;
          if (s2.empty())
          return s1;

          string laced;
          laced.resize(s1.size() + s2.size());
          
          int i = 0, pos = 0;
          int size = std::min(s1.size(), s2.size());
          
          // interlace common lengths substrings
          for ( ; i < size; ++i)
          {
              laced\[pos++\] = s1\[i\];
              laced\[pos++\] = s2\[i\];
          }
          
          // append the remainder of longer string
          if (s1.size() >= s2.size())
              for ( ; i < s1.size(); ++i)
                  laced\[pos++\] = s1\[i\];
          else
              for ( ; i < s2.size(); ++i)
                  laced\[pos++\] = s2\[i\];
          
          return laced;
          

          }

          A Offline
          A Offline
          Abhinav S
          wrote on last edited by
          #4

          Wrong forum.

          Apps - Color Analyzer | Arctic | XKCD | Sound Meter | Speed Dial

          1 Reply Last reply
          0
          • D Dave Kreskowiak

            Sorry, but that's not how it works. We're not here to do your work for you. We'll help if you've got a specific question or problem.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak

            B Offline
            B Offline
            BlackHat Umbrella
            wrote on last edited by
            #5

            { ("Let me see your code sir"); }

            1 Reply Last reply
            0
            • E ege yay

              string laceStrings(const string& s1, const string& s2)
              {
              if (s1.empty())
              return s2;
              if (s2.empty())
              return s1;

              string laced;
              laced.resize(s1.size() + s2.size());
              
              int i = 0, pos = 0;
              int size = std::min(s1.size(), s2.size());
              
              // interlace common lengths substrings
              for ( ; i < size; ++i)
              {
                  laced\[pos++\] = s1\[i\];
                  laced\[pos++\] = s2\[i\];
              }
              
              // append the remainder of longer string
              if (s1.size() >= s2.size())
                  for ( ; i < s1.size(); ++i)
                      laced\[pos++\] = s1\[i\];
              else
                  for ( ; i < s2.size(); ++i)
                      laced\[pos++\] = s2\[i\];
              
              return laced;
              

              }

              T Offline
              T Offline
              thatraja
              wrote on last edited by
              #6

              Next time use Google & find write forum before posting questions. Found this one[^] from Github. And alternatively you could Code Rewrite[^]

              thatraja

              Please update this article Useful Reference Books, it's urgent for Q/A section

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups