Click here to Skip to main content
14,039,045 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hello, i have a 2D array which has the dimensions of [9, 9] it is formatted like this:

Berzas,su
la;;sula;
;klevu sa
ldial lap
asula  a 
  aula, a
r  suart 
zemes vai
kai du   


My starting text file which i have formatted into the array above:

Berzas,sula;;sula;;klevu saldial lapasula  a   aila, ar  suart zemes vaikai du   


I need to find the amount of times these words appear in the array using recursion:

Sula
Alus


The output should be:

Sula 3
Alus 2


What I have tried:

I've only read the text file and formatted it into a array.

string file = File.ReadAllText(@"C:\Users\Justas\Desktop\L1\Rekursija\Trecias.txt");


         string[,] array = new string[n, n];

           var list = Enumerable
           .Range(0, file.Length / n)
           .Select(i => file.Substring(i * n, n))
           .ToList();

           var res = string.Join(Environment.NewLine, list);
           for (int i = 0; i < n; i++)
           {
               char[] row = list[i].ToCharArray();
               for (int j = 0; j < n; j++)
               {
                   array[i, j] = row[j].ToString();
               }
           }

           int rowLength = array.GetLength(0);
           int colLength = array.GetLength(1);


I am out of ideas on how to go about this problem. Any help would be greatly appreciated
Posted
Updated 5-Mar-19 8:18am
Comments
Gerry Schmitz 5-Mar-19 13:25pm
   
What's the point of the array? Flatten it out to a list and query that.
Member 14172040 5-Mar-19 13:46pm
   
Because its for an assignment and i have to use a 2D array
Patrice T 5-Mar-19 16:56pm
   
I am stuck on 1 thing: By hell, why do you want to use recursion in a problem that don't need recursion ?

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!

Start by thinking about how you would go about it manually and work that out carefully.
When you are sure that your method works each time, write it down.
Now do it again, following your own instructions absolutely. If it works, great! If it doesn't, modify the instructions until it does.

Now you have an algorithm, and can start by think about how to translate that into a design, and then code.
Then test it. And test it again with different data. Use the debugger to find out why it doesn't work when it fails.

This is an exercise in thinking and planning more than coding - though the coding is important too - it's there to get you started on "how do I do this?" rather than just blindly coding a design that you are fed with.

You'll get there - you just need to spend more time thinking, and a lot less coding!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.190425.1 | Last Updated 5 Mar 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100