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. How to Finding Solutions

How to Finding Solutions

Scheduled Pinned Locked Moved C#
tutorialquestion
20 Posts 9 Posters 1 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.
  • L Lost User

    Hello Experts, If i have a string "abc". then how can i get the shown output a b c ab bc ac abc In this output i do't need of ba or cab or cba. Thanks

    If you can think then I Can.

    B Offline
    B Offline
    BobJanova
    wrote on last edited by
    #3

    Homework question? Should the output contain ACB? or strictly ordered?

    1 Reply Last reply
    0
    • L Lost User

      Hello Experts, If i have a string "abc". then how can i get the shown output a b c ab bc ac abc In this output i do't need of ba or cab or cba. Thanks

      If you can think then I Can.

      E Offline
      E Offline
      Estys
      wrote on last edited by
      #4

      A double iteration over the input string with position and substring length :

              string str = "anystring";
      
              for (int x = 1; x <= str.Length; x++) // x = substring length
              {
                  for (int y = 0; y <= str.Length - x; y++) // y = start position
                  {
                      Console.WriteLine(str.Substring(y, x));
                  }
              }
      

      Cheers

      L 1 Reply Last reply
      0
      • E Estys

        A double iteration over the input string with position and substring length :

                string str = "anystring";
        
                for (int x = 1; x <= str.Length; x++) // x = substring length
                {
                    for (int y = 0; y <= str.Length - x; y++) // y = start position
                    {
                        Console.WriteLine(str.Substring(y, x));
                    }
                }
        

        Cheers

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #5

        Hello Estys, Thanks for your solution.But it is missing values. Input : ABC Output : A B C AB BC CA // Missing Value SO pls provide the solution for that.

        If you can think then I Can.

        E 1 Reply Last reply
        0
        • B Blue_Boy

          Is this, what you are looking for?

          string value="abc";
          string result=string.Empty;

          for(int i=0;i<=value.Length-1;i++)
          {
          result+=value[i].ToString()+"\n";
          }

          for(int i=0;i<=value.Length-1;i++)
          {
          if(i


          I Love T-SQL
          "VB.NET is developed with C#.NET"
          If my post helps you kindly save my time by voting my post.

          www.cacttus.com

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #6

          The Length of value is not fixed for 3 it can be increase and the result will be change according to input. then how can i do that.

          If you can think then I Can.

          B 1 Reply Last reply
          0
          • L Lost User

            The Length of value is not fixed for 3 it can be increase and the result will be change according to input. then how can i do that.

            If you can think then I Can.

            B Offline
            B Offline
            Blue_Boy
            wrote on last edited by
            #7

            Length of string is dynamic too on my example. Did you try my code to see result? Which is result for you if the string is "abcd"


            I Love T-SQL "VB.NET is developed with C#.NET" If my post helps you kindly save my time by voting my post. www.cacttus.com

            L 1 Reply Last reply
            0
            • L Lost User

              Hello Estys, Thanks for your solution.But it is missing values. Input : ABC Output : A B C AB BC CA // Missing Value SO pls provide the solution for that.

              If you can think then I Can.

              E Offline
              E Offline
              Estys
              wrote on last edited by
              #8

              I didn't see the "CA" value, ouch! Can you give an example of the expected output if the input is "ABCD"? Or perhaps describe the situation in words? I suspect you're going to need some recursive algorithm. Cheers

              B B 2 Replies Last reply
              0
              • L Lost User

                Hello Experts, If i have a string "abc". then how can i get the shown output a b c ab bc ac abc In this output i do't need of ba or cab or cba. Thanks

                If you can think then I Can.

                P Offline
                P Offline
                Pravin Patil Mumbai
                wrote on last edited by
                #9

                I found some good links : 1. http://n1b-algo.blogspot.com/2009/01/string-permutations.html[^] 2. http://geeksforgeeks.org/?p=767[^] 3. http://stackoverflow.com/questions/361/generate-list-of-all-possible-permutations-of-a-string[^] Hope this helps. All the best.

                D 1 Reply Last reply
                0
                • P Pravin Patil Mumbai

                  I found some good links : 1. http://n1b-algo.blogspot.com/2009/01/string-permutations.html[^] 2. http://geeksforgeeks.org/?p=767[^] 3. http://stackoverflow.com/questions/361/generate-list-of-all-possible-permutations-of-a-string[^] Hope this helps. All the best.

                  D Offline
                  D Offline
                  David1987
                  wrote on last edited by
                  #10

                  But he isn't asking for permutations..

                  P 1 Reply Last reply
                  0
                  • E Estys

                    I didn't see the "CA" value, ouch! Can you give an example of the expected output if the input is "ABCD"? Or perhaps describe the situation in words? I suspect you're going to need some recursive algorithm. Cheers

                    B Offline
                    B Offline
                    Blue_Boy
                    wrote on last edited by
                    #11

                    Estys wrote:

                    input is "ABCD"?

                    Same question I asked :)


                    I Love T-SQL "VB.NET is developed with C#.NET" If my post helps you kindly save my time by voting my post. www.cacttus.com

                    E 1 Reply Last reply
                    0
                    • E Estys

                      I didn't see the "CA" value, ouch! Can you give an example of the expected output if the input is "ABCD"? Or perhaps describe the situation in words? I suspect you're going to need some recursive algorithm. Cheers

                      B Offline
                      B Offline
                      BobJanova
                      wrote on last edited by
                      #12

                      CA wasn't in the initial spec, but AC was. The OP needs to better define what the problem actually is (and why he wants to solve it beyond 'my homework says so').

                      E 1 Reply Last reply
                      0
                      • B Blue_Boy

                        Length of string is dynamic too on my example. Did you try my code to see result? Which is result for you if the string is "abcd"


                        I Love T-SQL "VB.NET is developed with C#.NET" If my post helps you kindly save my time by voting my post. www.cacttus.com

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #13

                        the result by program is : a b c d ab bc cd abcd But Required result is : a b c d ab bc cd da bd abc bcd dab .... abcd ..etc

                        If you can think then I Can.

                        1 Reply Last reply
                        0
                        • B BobJanova

                          CA wasn't in the initial spec, but AC was. The OP needs to better define what the problem actually is (and why he wants to solve it beyond 'my homework says so').

                          E Offline
                          E Offline
                          Estys
                          wrote on last edited by
                          #14

                          You're right of course from a professional viewpoint. Some people, non-native english speakers, have trouble finding the right phrasing of the question though, which leads to this kind of confusion. I took a look at his profile, very interesting. Personally, I usually like solving these kindergarten puzzles, even if it sounds like homework :) . Cheers

                          B 1 Reply Last reply
                          0
                          • B Blue_Boy

                            Estys wrote:

                            input is "ABCD"?

                            Same question I asked :)


                            I Love T-SQL "VB.NET is developed with C#.NET" If my post helps you kindly save my time by voting my post. www.cacttus.com

                            E Offline
                            E Offline
                            Estys
                            wrote on last edited by
                            #15

                            Blue_Boy wrote:

                            Same question I asked

                            Great minds think alike :-D .

                            If you can read this, you don't have Papyrus installed

                            1 Reply Last reply
                            0
                            • B Blue_Boy

                              Is this, what you are looking for?

                              string value="abc";
                              string result=string.Empty;

                              for(int i=0;i<=value.Length-1;i++)
                              {
                              result+=value[i].ToString()+"\n";
                              }

                              for(int i=0;i<=value.Length-1;i++)
                              {
                              if(i


                              I Love T-SQL
                              "VB.NET is developed with C#.NET"
                              If my post helps you kindly save my time by voting my post.

                              www.cacttus.com

                              H Offline
                              H Offline
                              HTT90
                              wrote on last edited by
                              #16

                              Backtracking . You can search google to more detail . I can it useful for you . Thanks !!

                              1 Reply Last reply
                              0
                              • L Lost User

                                Hello Experts, If i have a string "abc". then how can i get the shown output a b c ab bc ac abc In this output i do't need of ba or cab or cba. Thanks

                                If you can think then I Can.

                                P Offline
                                P Offline
                                PIEBALDconsult
                                wrote on last edited by
                                #17

                                Maybe this[^] will help.

                                1 Reply Last reply
                                0
                                • L Lost User

                                  Hello Experts, If i have a string "abc". then how can i get the shown output a b c ab bc ac abc In this output i do't need of ba or cab or cba. Thanks

                                  If you can think then I Can.

                                  A Offline
                                  A Offline
                                  Alan Balkany
                                  wrote on last edited by
                                  #18

                                  What you're looking for is the power set of "abc" (http://en.wikipedia.org/wiki/Power_set[^] ) If you go through all the 3-bit numbers (000, 001, 010, 011...) (i.e. the power set) and use the letters corresponding to 1's, that will give you all the permutations.

                                  1 Reply Last reply
                                  0
                                  • E Estys

                                    You're right of course from a professional viewpoint. Some people, non-native english speakers, have trouble finding the right phrasing of the question though, which leads to this kind of confusion. I took a look at his profile, very interesting. Personally, I usually like solving these kindergarten puzzles, even if it sounds like homework :) . Cheers

                                    B Offline
                                    B Offline
                                    Blue_Boy
                                    wrote on last edited by
                                    #19

                                    Based on his/her profile description, he/she should be able to solve that problem.


                                    I Love T-SQL "VB.NET is developed with C#.NET" If my post helps you kindly save my time by voting my post. www.cacttus.com

                                    1 Reply Last reply
                                    0
                                    • D David1987

                                      But he isn't asking for permutations..

                                      P Offline
                                      P Offline
                                      Pravin Patil Mumbai
                                      wrote on last edited by
                                      #20

                                      I think he is asking combination.....

                                      I quit being afraid when my first venture failed and the sky didn't fall down.

                                      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