C code works in Visual Studio 2019 but not in online compiler

0 votes

I'm taking online tests right now. The code runs OK in Visual Studio 2019, but it fails when I submit it. Many compilation problems are thrown by other online compilers as well. The following are the parameters for the online testing environment: DMCS version of Mono C#, compiler version 4.6.2.0 with the flags: -optimize+ -r:System.Numerics {files}

I tried changing the.NET target framework to 4, but my PC didn't give me any issues. How can I get Visual Studio to use the same settings as the example above?

using System; using System.Collections.Generic;

namespace capgemini_kattis { class Program { static void Main(string[] args) {

        /*
        >>>>>>>>>>>>>>>>>>>>>>>>>>>>>Task 2
        */
        bool isNumberOfCommandsRead = false;
        List<string> answer = new List<string>();
        string input = "????????????????????????????????";
        Char[] charArray = input.ToCharArray();
        int numberOfCommands = 0;
        string line;

        void CLEAR(int i)
        {
            charArray[i] = '0';
        }
        void SET(int i)
        {
            charArray[i] = '1';
        }
        void OR(int i, int j)
        {
            if (charArray[i] == '1' || charArray[j] == '1')
            {
                charArray[i] = '1';
            }
            else if (charArray[i] == '0' && charArray[j] == '0')
            {
                charArray[i] = '0';
            }
            else
            {
                charArray[i] = '?';
            }
        }
        void AND(int i, int j)
        {
            if (charArray[i] == '1' && charArray[j] == '1')
            {
                charArray[i] = '1';
            }
            else if (charArray[i] == '0' || charArray[j] == '0')
            {
                charArray[i] = '0';
            }
            else
            {
                charArray[i] = '?';
            }
        }

        while ((line = Console.ReadLine()) != null)
        {
            if (!isNumberOfCommandsRead)
            {
                numberOfCommands = Convert.ToInt32(line.Trim());
                isNumberOfCommandsRead = true;
                if (numberOfCommands == 0)
                {
                    break;
                }
            }


            else
            {
                string[] split = line.Split(new char[] { ' ' }, StringSplitOptions.None);

                switch (split[0].Trim().ToUpper())
                {
                    case "CLEAR":
                        CLEAR(Convert.ToInt32(split[1].Trim()));
                        numberOfCommands--;
                        break;

                    case "SET":
                        SET(Convert.ToInt32(split[1].Trim()));
                        numberOfCommands--;
                        break;

                    case "OR":
                        OR(Convert.ToInt32(split[1].Trim()), Convert.ToInt32(split[2].Trim()));
                        numberOfCommands--;
                        break;

                    case "AND":
                        AND(Convert.ToInt32(split[1].Trim()), Convert.ToInt32(split[2].Trim()));
                        numberOfCommands--;
                        break;
                }


                if (numberOfCommands == 0)
                {
                    Array.Reverse(charArray);
                    string sectionResult = "";
                    for (int i = 0; i < (new string(charArray)).Length; i++)
                    {
                        sectionResult += charArray[i].ToString();
                        charArray[i] = '?';
                    }
                    answer.Add(sectionResult);
                    sectionResult = null;
                    isNumberOfCommandsRead = false;
                }
            }
        }

        foreach (string s in answer)
        {
            Console.WriteLine(s);
        }
        Console.ReadLine();
    }
}
}
May 27, 2022 in Others by pranav
• 2,580 points
216 views

1 answer to this question.

0 votes
Repl.it compiles in Mono C# 4.6.2.0, according to my research. It helps in dealing with the issue and resolving it.
answered May 30, 2022 by rajiv
• 1,620 points

Related Questions In Others

0 votes
1 answer

Download file from URL in Excel 2019 (it works on Excel 2007)

The Sub Code looks fine. Check the ...READ MORE

answered Oct 7, 2022 in Others by narikkadan
• 50,080 points
255 views
0 votes
1 answer

Text with a dash in the cell but not in the formula bar (Excel)

What you have got here is called ...READ MORE

answered Nov 13, 2022 in Others by narikkadan
• 50,080 points
77 views
0 votes
1 answer

Excel MATCH function is not working on an array but works once directed to the matched value

According to the definition here: support.microsoft.com/en-us/office/… if you do ...READ MORE

answered Nov 17, 2022 in Others by narikkadan
• 50,080 points
73 views
0 votes
1 answer

Excel SUM function is not working (shows 0), but using Addition (+) works

The values in A1 and A2 are ...READ MORE

answered Jan 5 in Others by narikkadan
• 50,080 points
39 views
0 votes
0 answers

C# code works in Visual Studio 2019 but not in online compiler

I'm taking tests online. The code runs ...READ MORE

Sep 26, 2022 in C# by krishna
• 2,820 points
83 views
0 votes
0 answers

Compiling New C# Versions (C# 7.0 Higher) From The Command Line

When I use Microsoft's Visual C# Compiler ...READ MORE

May 27, 2022 in Others by pranav
• 2,580 points
203 views
0 votes
1 answer

Mono C# tutorial?

For learning the language, any C# tutorial ...READ MORE

answered May 30, 2022 in C# by rajiv
• 1,620 points
170 views
0 votes
1 answer

How can I compile and run c# program without using visual studio

If you have.NET Framework v4 installed, then C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe ...READ MORE

answered Jun 9, 2022 in C# by rajiv
• 1,620 points
181 views
0 votes
1 answer

What's the strangest corner case you've seen in C# or .NET?

Bankers' Rounding is a term that refers ...READ MORE

answered May 30, 2022 in Others by rajiv
• 1,620 points
84 views
0 votes
1 answer

Disable Postback on button ASP.NET c#

If you're dynamically adding controls to the ...READ MORE

answered May 30, 2022 in Others by rajiv
• 1,620 points
1,697 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP