Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want to convert C++ code to C#. C++ Code: #include #include #include using namespace std; int main() { int

I want to convert C++ code to C#.

 

C++ Code:

 

 

#include
#include
#include

using namespace std;

 

int main()
{
   int t;
   cin >> t;

   for (int i = 0; i < t; i++)
   {
       int w, h, n;
       cin >> w >> h >> n;

       vector map1(h);
       vector map2(h);

       for (int j = 0; j < h; j++)
       {
           cin >> map1[j];
       }

       for (int j = 0; j < h; j++)
       {
           cin >> map2[j];
       }

       vector> shots;

       for (int j = 0; j < n; j++)
       {
           int x, y;
           cin >> x >> y;
           shots.push_back({x, y});
       }

       int score1 = 0;
       int score2 = 0;
       int player = 1;

       for (auto& shot : shots)
       {
           int x = shot.first;
           int y = shot.second;

           if (player == 1)
           {
               if (map2[y][x] == '#')
               {
                   score1++;
                   player = 2;
               }
               else
               {
                   player = 2;
               }
           }
           else
           {
               if (map1[y][x] == '#')
               {
                   score2++;
                   player = 1;
               }
               else
               {
                   player = 1;
               }
           }
       }

       cout << "Player " << (score1 > score2 ? 1 : 2) << " won." << endl;
   }

   return 0;
}


Step by Step Solution

There are 3 Steps involved in it

Step: 1

Here is the C equivalent of the provided C code csharp using System using SystemCollectionsG... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual C# An Introduction to Object-Oriented Programming

Authors: Joyce Farrell

7th edition

978-1337102100

Students also viewed these Programming questions