Skip to content

Instantly share code, notes, and snippets.

@laur3d
Last active February 9, 2021 08:59
Show Gist options
  • Save laur3d/91dcb99e9858a7f2f8fd49473457b5c1 to your computer and use it in GitHub Desktop.
Save laur3d/91dcb99e9858a7f2f8fd49473457b5c1 to your computer and use it in GitHub Desktop.
class Solution
{
static void Main(string[] args)
{
int L = int.Parse(Console.ReadLine());
int H = int.Parse(Console.ReadLine());
var writter = new Writer(H,L);
string T = Console.ReadLine();
for (int i = 0; i < H; i++)
{
writter.PopulateLetters(Console.ReadLine());
}
writter.ToAsciiString(T, true);
}
}
class Letter
{
public int height { get; private set; }
public int width { get; private set; }
public int startPoint { get; private set; }
public List<string> AsciiMatrix;
private Letter() { }
public Letter(int h, int w, int s)
{
AsciiMatrix = new List<string>();
height = h;
width = w;
startPoint = s;
}
public void AddRow(string row)
{
AsciiMatrix.Add(row.Substring(this.startPoint, width));
}
}
class Writer
{
public Dictionary<char, Letter> dict = new Dictionary<char, Letter>();
private string charList = "ABCDEFGHIJKLMNOPQRSTUVWXYZ?";
private int height;
public Writer(int h, int w)
{
charList
.ToCharArray()
.ToList()
.ForEach(c => dict.Add(c, new Letter(h, w, charList.IndexOf(c) * w )));
height = h;
}
public void PopulateLetters(string row)
{
foreach (KeyValuePair<char, Letter> entry in dict)
{
entry.Value.AddRow(row);
}
}
public List<string> ToAsciiString(string s, bool print)
{
var searchString = string.Join("" , s.ToUpper().ToCharArray().ToList().Select(x =>
{
return charList.Contains(x) ? x : '?';
}).ToList());
List<string> buffer = new List<string>();
for (int i = 0; i < height; i++)
{
List<string> lineBuffer = new List<string>();
searchString.ToCharArray().ToList().ForEach(e =>
{
lineBuffer.Add(dict[e].AsciiMatrix[i]);
});
buffer.Add(string.Join("", lineBuffer));
}
foreach(string row in buffer){
Console.WriteLine($"{row}");
}
return buffer;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment