Jump to content

Need help with code

Vuk

Ok so, I have some problems with my coding task. I have to create a program that will find the smallest character in a string from user inputted place in string, however much times user wants.

I have created this garbage of code and I've gotten an error on my second input, but not on the first one.

Also I've filled the list with 6 Char.MaxValues for testing because I don't know how else to do it. I'd appreciate help in solving that.

The input/output should look like this:

6 2

abcdef

2 6

b

4 6

d

Disclaimer: I'm just a noob in programming so don't hate :)

 

static void Main(string[] args)
        {
            int N, Q, L, R;
            string S;

            string[] temp = Console.ReadLine().Split(' ');
            N = int.Parse(temp[0]); Q = int.Parse(temp[1]);
            S = Console.ReadLine();

            List<char> cTemp = new List<char>() { Char.MaxValue, Char.MaxValue, Char.MaxValue, Char.MaxValue, Char.MaxValue, Char.MaxValue }; char min = Char.MinValue;
            int k;

            for (int i = 0; i < Q; i++)
            {
                temp = Console.ReadLine().Split(' ');
                L = int.Parse(temp[0]); R = int.Parse(temp[1]);
                k = 0;
                while (L < R)
                {
                    cTemp[L - 1] = S[L - 1];
                    if(k == 0) if (cTemp[L - 1] < cTemp[L - 2])
                        min = cTemp[L - 1];
                    k++; L++;
                }
                Console.WriteLine(min);
                cTemp.Clear();
            }
        }

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×