iliya87

05.ByteParty

Mar 23rd, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.64 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ByteParty
  8. {
  9.     class ByteParty
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int count = int.Parse(Console.ReadLine());
  14.             int[] n = new int[count];
  15.             for (int i = 0; i < n.Length; i++)
  16.             {
  17.                 n[i] = int.Parse(Console.ReadLine());
  18.             }
  19.             //n = n ^ (1 << pos);     // обръща бит-а на дадена позиция (0 -> 1 или 1 -> 0)
  20.  
  21.             //n = n & ~(1 << pos);     // прави бит-а 0-ла
  22.  
  23.             //n = n | (1 << pos);     // прави бит-а 1-ца
  24.  
  25.             while (true)
  26.             {
  27.                 string[] inputcommand = Console.ReadLine().Split();
  28.                 if (inputcommand[0] == "party")
  29.                 {
  30.                     break;
  31.                 }
  32.                 string command = inputcommand[0];
  33.                 int pos = int.Parse(inputcommand[1]);
  34.  
  35.                 for (int i = 0; i < n.Length; i++)
  36.                 {
  37.                     if (command == "-1")
  38.                     {
  39.                         n[i] ^= 1 << pos;
  40.                     }
  41.                     if (command == "0")
  42.                     {
  43.                         n[i] &= (-1 << pos);
  44.                     }
  45.                     if (command == "1")
  46.                     {
  47.                         n[i] |= 1 << pos;
  48.                     }
  49.                 }
  50.             }
  51.             for (int i = 0; i < n.Length; i++)
  52.             {
  53.                 Console.WriteLine(n[i]);
  54.             }
  55.         }
  56.  
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment