Skip to content

Instantly share code, notes, and snippets.

@Kiso-blg
Created March 13, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kiso-blg/0a6489d35c86d2d28f47 to your computer and use it in GitHub Desktop.
Save Kiso-blg/0a6489d35c86d2d28f47 to your computer and use it in GitHub Desktop.
C# Basics December 2014 Lab
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