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 7558153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:18:00+00:00 2026-05-30T12:18:00+00:00

I want to check if string1 can be made by taking characters from string2

  • 0

I want to check if string1 can be made by taking characters from string2 and putting them in the right order. What would be the most effective way to do that?

For example, I have 2 strings as shown below:

string s1 = "ABCDASFSADFAF", s2 ="ABCDFGSAGSRASFSFASFASDADFAFDSAGFAS";

as you can see, we can make string s1 from the characters in string s2, so string1 exists in string2. So basically, I need to check if you can make string s1 from string s2. what would be the most effective way to do something like that? I had an idea, to go through with loop, and check how many times each letter is in string, and then do the same with second string, then just compare the array’s with stored information, and if string s2 letter array has more or equal to string s1 array letters, then we will be able to make s1 from s2.

Oh and programming language is C++.

  • 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-05-30T12:18:02+00:00Added an answer on May 30, 2026 at 12:18 pm

    You can check for this by looping through s1 and removing the first find of each character from a copy of s2:

    #include <string.h>
    
    using namespace std;
    
    string s1 = "ABCC", s2 = "DCBA";
    
    string copy = s2;
    size_t found;
    bool contains = true;
    
    for(int i = 0; i < s1.length(); i++)
    {
        found = copy.find(s1[i]);
        if(found == string::npos)
        {
            contains = false;
            break;
        }
        copy = copy.replace(found, 1, "");
    }
    
    // Now 'contains' is true if s1 can be made from s2, false if it can't.
    // If also 'copy' is empty, s1 is an anagram of s2.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i made check box in wpf ,Got it from Internet.I want to see which
I have a String2. I want to check whether String2 exists in String1. String1's
i want to set RegularExpressions for check string1. string1 can change to : string1:='D1413578;1038'
I want to check if string doesn't have more than 5 numbers. I can
I want something that can check if a string is SELECT , INSERT ,
If I want to check for the null string I would do [ -z
I want to check that Java String or character array is not just made
I want to check if a string object of 20 characters has only null
I want to check whether a string is a file name (name DOT ext)
I want to I check whether a string is in ASCII or not. I

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.