Created
March 13, 2016 08:41
-
-
Save Kiso-blg/0a6489d35c86d2d28f47 to your computer and use it in GitHub Desktop.
C# Basics December 2014 Lab
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace _04.Tetris | |
{ | |
class Tetris | |
{ | |
static void Main(string[] args) | |
{ | |
string[] size = Console.ReadLine().Split(' '); | |
int rows = int.Parse(size[0]); | |
int cols = int.Parse(size[1]); | |
long[] sequence = GetField(rows, cols); | |
int figureI = GetFigureI(sequence, rows, cols); | |
int figureL = GetFigureL(sequence, rows, cols); | |
int figureJ = GetFigureJ(sequence, rows, cols); | |
int figureO = GetFigureO(sequence, rows, cols); | |
int figureZ = GetFigureZ(sequence, rows, cols); | |
int figureS = GetFigureS(sequence, rows, cols); | |
int figureT = GetFigureT(sequence, rows, cols); | |
Console.WriteLine("I:{0}, L:{1}, J:{2}, O:{3}, Z:{4}, S:{5}, T:{6}", | |
figureI, figureL, figureJ, figureO, figureZ, figureS, figureT); | |
} | |
private static int GetFigureT(long[] sequence, int rows, int cols) | |
{ | |
int count = 0; | |
for (int row = 0; row < rows - 1; row++) | |
{ | |
for (int col = 0; col < cols - 2; col++) | |
{ | |
if (((sequence[row] >> col) & 1) == 1) | |
{ | |
if (((sequence[row] >> col + 1) & 1) == 1 && | |
((sequence[row] >> col + 2) & 1) == 1 && | |
((sequence[row + 1] >> (col + 1)) & 1) == 1) | |
{ | |
count++; | |
} | |
} | |
} | |
} | |
return count; | |
} | |
private static int GetFigureS(long[] sequence, int rows, int cols) | |
{ | |
int count = 0; | |
for (int row = 0; row < rows - 1; row++) | |
{ | |
for (int col = 1; col < cols - 1; col++) | |
{ | |
if (((sequence[row] >> col) & 1) == 1) | |
{ | |
if (((sequence[row] >> col + 1) & 1) == 1 && | |
((sequence[row + 1] >> col) & 1) == 1 && | |
((sequence[row + 1] >> (col - 1)) & 1) == 1) | |
{ | |
count++; | |
} | |
} | |
} | |
} | |
return count; | |
} | |
private static int GetFigureZ(long[] sequence, int rows, int cols) | |
{ | |
int count = 0; | |
for (int row = 0; row < rows - 1; row++) | |
{ | |
for (int col = 0; col < cols - 2; col++) | |
{ | |
if (((sequence[row] >> col) & 1) == 1) | |
{ | |
if (((sequence[row] >> col + 1) & 1) == 1 && | |
((sequence[row + 1] >> col +1 ) & 1) == 1 && | |
((sequence[row + 1] >> (col + 2)) & 1) == 1) | |
{ | |
count++; | |
} | |
} | |
} | |
} | |
return count; | |
} | |
private static int GetFigureO(long[] sequence, int rows, int cols) | |
{ | |
int count = 0; | |
for (int row = 0; row < rows - 1; row++) | |
{ | |
for (int col = 0; col < cols - 1; col++) | |
{ | |
if (((sequence[row] >> col) & 1) == 1) | |
{ | |
if (((sequence[row] >> col + 1) & 1) == 1 && | |
((sequence[row + 1] >> col) & 1) == 1 && | |
((sequence[row + 1] >> (col + 1)) & 1) == 1) | |
{ | |
count++; | |
} | |
} | |
} | |
} | |
return count; | |
} | |
private static int GetFigureJ(long[] sequence, int rows, int cols) | |
{ | |
int count = 0; | |
for (int row = 0; row < rows - 2; row++) | |
{ | |
for (int col = 1; col < cols; col++) | |
{ | |
if (((sequence[row] >> col) & 1) == 1) | |
{ | |
if (((sequence[row + 1] >> col) & 1) == 1 && | |
((sequence[row + 2] >> col) & 1) == 1 && | |
((sequence[row + 2] >> (col - 1)) & 1) == 1) | |
{ | |
count++; | |
} | |
} | |
} | |
} | |
return count; | |
} | |
private static int GetFigureL(long[] sequence, int rows, int cols) | |
{ | |
int count = 0; | |
for (int row = 0; row < rows - 2; row++) | |
{ | |
for (int col = 0; col < cols - 1; col++) | |
{ | |
if (((sequence[row] >> col) & 1) == 1) | |
{ | |
if (((sequence[row + 1] >> col) & 1) == 1 && | |
((sequence[row + 2] >> col) & 1) == 1 && | |
((sequence[row + 2] >> (col + 1)) & 1) == 1) | |
{ | |
count++; | |
} | |
} | |
} | |
} | |
return count; | |
} | |
private static int GetFigureI(long[] sequence, int rows, int cols) | |
{ | |
int count = 0; | |
for (int row = 0; row < rows - 3; row++) | |
{ | |
for (int col = 0; col < cols; col++) | |
{ | |
if (((sequence[row] >> col) & 1) == 1) | |
{ | |
if (((sequence[row + 1] >> col) & 1) == 1 && | |
((sequence[row + 2] >> col) & 1) == 1 && | |
((sequence[row + 3] >> col) & 1) == 1) | |
{ | |
count++; | |
} | |
} | |
} | |
} | |
return count; | |
} | |
private static long[] GetField(int rows, int cols) | |
{ | |
long[] field = new long[rows]; | |
for (int row = 0; row < rows; row++) | |
{ | |
string inputRow = Console.ReadLine().ToLower(); | |
for (int col = 0; col < cols; col++) | |
{ | |
if (inputRow[col] == 'o') | |
{ | |
field[row] |= ((long)1 << col); | |
} | |
} | |
} | |
return field; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment