Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
111
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.RegularExpressions;
using System.Text;
using System;
namespace HackerRank
{
static class Helper
{
}
class Program
{
static int I(string str, int index)
{
if (str == null) return -1;
if (str.Length <= 0) return 0;
int length = str.Length;
int b = index < 0 ? length - (index % length) : index;
return b % length;
}
static bool nearby(char who, string where, int near)
{
return (where[I(where,near+1)] == who || where[I(where, near - 1)] == who);
}
static bool near_left(string b,int j,string a, int i)
{
return nearby(b[I(b, j - 1)], a, i);
}
static bool near_right(string b, int j, string a, int i)
{
return nearby(b[I(b, j + 1)], a, i);
}
static int makeAnagram(string a, string b)
{
int a_l = a.Length;
int b_l = b.Length;
bool near = false;
for (int j = 0; j < b_l; j++) //позиция буквы в строке `b`
{
char s = b[j];//берем из `b` одну букву
List<int> searched = new List<int>();
for (int i = 0; i < a_l; i++)
{
if (a[i] == s) searched.Add(i); //и ищем эту букву в `a`
}
if (searched.Count > 0)
{
foreach (int i in searched) // индекс найденноой буквы в строке `a`
{
if (near_left(b, j, a, i))
{
near = true;Console.WriteLine("Founded Left");}
if (near_right(b, j, a, i))
{
near = true;Console.WriteLine("Founded Right");}
}
Console.WriteLine();
}
}
return -1;
}
static void Main(string[] args)
{
Console.WriteLine(makeAnagram("fcrxzwscanmligyxyvym", "jxwtrhvujlmrpdoqbisbwhmgpmeoke"));
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.