using System.Collections.Generic;
readonly StreamReader _input;
readonly Dictionary<string, char> _str2Char;
public Transformer(Stream stream, Dictionary<string, char> str2Char) {
_input = new StreamReader(stream);
public Stream Transfrom() {
var output = new StreamWriter(new MemoryStream());
var buffer = new StringBuilder();
while ((c = _input.Read()) != -1) {
if (buffer.Length >= 2) {
var str = buffer.ToString();
bool isSpecialCase = str == "Key" && ch == 'O';
WriteToOutput(str, output);
WriteToOutput(buffer.ToString(), output);
return output.BaseStream;
void WriteToOutput(string str, StreamWriter output) {
if (_str2Char.TryGetValue(str, out c))
public static void Main()
Dictionary<string, char> str2Char = new Dictionary<string, char> {
string str = "Hello!ReturnHowSpaceAreSpaceYouKeyOemcomma";
var input = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(str));
var t = new Transformer(input, str2Char);
var output = t.Transfrom();
output.Seek(0, SeekOrigin.Begin);
var s = new StreamReader(output);
while ((c = s.Read()) != -1) {