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

0 votes

I'm taking tests online. The code runs flawlessly in Visual Studio 2019 on my computer, but not when I submit it. Many compilation problems are produced by other online compilers as well. The settings for the online test environment are: Version 4.6.2.0 of the Mono C# compiler with the -optimize+ parameters for the DMCS version files for System.Numerics.

I attempted to switch the.NET target framework to 4, but my PC shows no issues. How do I set up Visual Studio with the same preferences as before?

My code:

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();
    }
}
}
Sep 26, 2022 in C# by krishna
• 2,820 points
486 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In C#

0 votes
1 answer

Is a Library a project or a C# source code file in Visual Studio?

A library project is a collection of ...READ MORE

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

Windows Form application on Visual Studio Code?

There is a simpler way to achieve ...READ MORE

answered Jun 7, 2022 in C# by pranav
• 2,590 points
8,245 views
0 votes
1 answer

Build a bot in Azure online code editor

Restart the Web App Bot and the ...READ MORE

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

What are the differences between C, C# and C++ in terms of real-world applications?

C is a bare-bones, straightforward, and clean ...READ MORE

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

Examples of dynamic polymorphism in c#

Check the example of polymorphism below. We ...READ MORE

answered Jun 7, 2022 in C# by pranav
• 2,590 points
858 views
0 votes
1 answer

Print Pdf in C#

Using an installed Adobe Reader or any ...READ MORE

answered Jun 7, 2022 in C# by pranav
• 2,590 points
834 views
0 votes
1 answer

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

Repl.it compiles in Mono C# 4.6.2.0, according ...READ MORE

answered May 30, 2022 in Others by rajiv
• 1,620 points
1,235 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,590 points
613 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
737 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
1,300 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