Advertisement
gospod1978

List-Ex/Cards game

Oct 19th, 2019
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace fundamental
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.  
  12.             List<int> listOne = Console.ReadLine().Split().Select(int.Parse).ToList();
  13.             List<int> listTwo = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.             while(listOne.Count != 0 && listTwo.Count != 0)
  15.             {
  16.            
  17.                 int count = 0;
  18.                
  19.            
  20.                 if (listOne.Count <= listTwo.Count)
  21.                 {
  22.                     count = listOne.Count;
  23.                 }
  24.                 else
  25.                 {
  26.                     count = listTwo.Count;
  27.                 }
  28.                 //Console.WriteLine(count);
  29.                 for (int i = 0; i < count; i++)
  30.                 {
  31.                     int current = 0;
  32.                     int current1 = 0;
  33.                
  34.                     if (listOne[i] < listTwo[i])
  35.                     {
  36.                         current = listOne[i];
  37.                         current1 = listTwo[i];
  38.                         listOne.RemoveAt(i);
  39.                         listTwo.RemoveAt(i);
  40.                         listTwo.Add(current1);
  41.                         listTwo.Add(current);
  42.                         break;
  43.                     }
  44.                     else if (listOne[i] > listTwo[i])
  45.                     {
  46.                         current = listOne[i];
  47.                         current1 = listTwo[i];
  48.                         listOne.RemoveAt(i);
  49.                         listTwo.RemoveAt(i);
  50.                         listOne.Add(current);
  51.                         listOne.Add(current1);
  52.                         break;
  53.                     }
  54.                     else if (listOne[i] == listTwo[i])
  55.                     {
  56.                         listOne.RemoveAt(i);
  57.                         listTwo.RemoveAt(i);
  58.                         break;
  59.                     }
  60.                 }
  61.             }
  62.            
  63.             if(listOne.Count > 0)
  64.             {
  65.                 Console.WriteLine($"First player wins! Sum: {listOne.Sum()}");
  66.             }
  67.             else
  68.             {
  69.                 Console.WriteLine($"Second player wins! Sum: {listTwo.Sum()}");
  70.             }
  71.            
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement