private bool CheckGameEnd(char[] gameField, char currentPlayer) { var result = false; var winString = new char[3]; //k - номера элемента массива winString //Запись столбца gameField в новый массив для проверки выигрыша for (var i = 0; i < 3; i++) { for (int j = 0, k = 0; j < gameField.Length; j += 3, k++) { winString[k] = gameField[j]; } //проверка выигрыша if (winString.All(T => T == currentPlayer)) { result = true; break; } } //Запись строки gameField в новый массив для проверки выигрыша for (var j = 0; j < gameField.Length; j += 3) { for (int i = 0, k = 0; i < 3; i++, k++) { winString[k] = gameField[i]; } if (winString.All(T => T == currentPlayer)) { result = true; break; } } //Проверка выигрыша по диагоналям Array.Clear(winString, 0, winString.Length); for (int i = 0, k = 0; i < gameField.Length; i += 4, k++) { winString[k] = gameField[i]; if (winString.All(T => T == currentPlayer)) { result = true; break; } } Array.Clear(winString, 0, winString.Length); for (int i = 2, k = 0; i < 7; i += 2, k++) { winString[k] = gameField[i]; if (winString.All(T => T == currentPlayer)) { result = true; break; } } return(result); }
public void GoForwardUntilEndBracket(params char[] inputArray) { List <char> asList = new List <char>(inputArray); char[] open = new char[inputArray.Length / 2]; Array.Copy(inputArray, open, inputArray.Length / 2); asList.RemoveRange(0, inputArray.Length / 2); char[] closed = asList.ToArray(); if (open.Contains('"')) { InSkipEmpty = true; } int parantheses = 0; do { if (open.Contains(Current) && (!open.All(v => closed.Contains(v)) || parantheses == 0)) { parantheses++; } else if (closed.Contains(Current)) { parantheses--; } GoForwardOne(); } while (parantheses != 0); InSkipEmpty = false; }
/// <summary> /// Parses a notation string into a LayerMoveCollection /// </summary> /// <param name="notation">Defines to string to be parsed</param> public static LayerMoveCollection Parse(string notation) { string layer = notation[0].ToString(); LayerMoveCollection moves = new LayerMoveCollection(); char[] ccwChars = new char[] { '\'', 'i' }; bool direction = !ccwChars.All(c => notation.Contains(c)); bool twice = notation.Contains("2"); switch (layer) { case "r": moves = new LayerMove(CubeFlag.RightSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSliceSides, direction, twice); break; case "l": moves = new LayerMove(CubeFlag.LeftSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSliceSides, !direction, twice); break; case "u": moves = new LayerMove(CubeFlag.TopLayer, direction, twice) & new LayerMove(CubeFlag.MiddleLayer, direction, twice); break; case "d": moves = new LayerMove(CubeFlag.BottomLayer, direction, twice) & new LayerMove(CubeFlag.MiddleLayer, !direction, twice); break; case "f": moves = new LayerMove(CubeFlag.FrontSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSlice, direction, twice); break; case "b": moves = new LayerMove(CubeFlag.BackSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSlice, !direction, twice); break; case "x": moves = new LayerMove(CubeFlag.RightSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSliceSides, direction, twice) & new LayerMove(CubeFlag.LeftSlice, !direction, twice); break; case "y": moves = new LayerMove(CubeFlag.TopLayer, direction, twice) & new LayerMove(CubeFlag.MiddleLayer, direction, twice) & new LayerMove(CubeFlag.BottomLayer, !direction, twice); break; case "z": moves = new LayerMove(CubeFlag.FrontSlice, direction, twice) & new LayerMove(CubeFlag.MiddleSlice, direction, twice) & new LayerMove(CubeFlag.BackSlice, !direction, twice); break; } return(moves); }
public string GetResult1() { SetScaffold(); int sum = 0; for (int y = 0; y < scaffold.Length; y++) { for (int x = 0; x < scaffold[y].Length; x++) { var left = GetPos(x - 1, y); var up = GetPos(x, y - 1); var right = GetPos(x + 1, y); var down = GetPos(x, y + 1); var here = GetPos(x, y); var all = new char[] { left, up, right, down, here }; if (all.All(ch => ch == '#')) { sum += x * y; } } } return(sum.ToString()); }
/// <summary> /// 判断是否为数字 /// </summary> /// <param name="str">字符串</param> /// <returns></returns> private static bool IsNumeric(string str) { var ch = new char[str.Length]; ch = str.ToCharArray(); return(ch.All(t => t >= 48 && t <= 57)); }
public static bool IsPangram(string str) { char[] alphabet = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; char[] condensedInput = str.ToLower().Distinct().OrderBy(c => c).ToArray(); return(alphabet.All(letter => condensedInput.Contains(letter))); }
static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var s = new char[n][]; for (int i = 0; i < n; i++) { s[i] = Console.ReadLine().ToCharArray(); } for (int i = 0; i < n; i++) { Array.Sort(s[i]); } bool f = true; var ans = new List <char>(); var c = new char[n]; var sc = new int[n]; for (int i = 0; i < n; i++) { c[i] = s[i][0]; sc[i] = 0; } while (true) { if (c.All(x => x == c[0])) { ans.Add(c[0]); for (int i = 0; i < n; i++) { sc[i]++; } } else { var cmin = c.Min(); for (int i = 0; i < n; i++) { if (c[i] == cmin) { sc[i]++; } } } for (int i = 0; i < n; i++) { if (sc[i] >= s[i].Length) { goto last; } c[i] = s[i][sc[i]]; } } last: Console.WriteLine(new String(ans.ToArray())); }
public void No_Arg_All_Values_Are_Between_Zero_And_MaxValue() { var chars = new char[Assertion.Amount]; for (var i = 0; i < Assertion.Amount; i++) { chars[i] = CharProvider.Char(); } chars.AssertNotAllValuesAreTheSame(); Assert.True( chars.All(x => x >= 0), "chars.All(x => x >= 0 && x < char.MaxValue)" ); }
public void Inclusive_Min_Arg() { var chars = new char[Assertion.Amount]; const char arg = 'h'; for (var i = 0; i < Assertion.Amount; i++) { chars[i] = CharProvider.Char(arg, arg); } Assert.True( chars.All(x => x == arg), "chars.All(x => x == arg)" ); }
public void All_Values_Are_Between_Zero_And_Max() { var chars = new char[Assertion.Amount]; const char max = 'z'; for (var i = 0; i < Assertion.Amount; i++) { chars[i] = CharProvider.Char(max); } chars.AssertNotAllValuesAreTheSame(); Assert.True( chars.All(x => x >= 0 && x <= max), "chars.All(x => x >= 0 && x <= max)" ); }
public void Inclusive_Max_Arg() { var chars = new char[Assertion.Amount]; const char max = char.MaxValue; const char min = max; for (var i = 0; i < Assertion.Amount; i++) { chars[i] = CharProvider.Char(min, max); } Assert.True( chars.All(x => x == min), "chars.All(x => x == min)" ); }
/// <summary> /// Valid Anagram (Mine) /// </summary> /// <param name="s"></param> /// <param name="t"></param> /// <returns></returns> public static bool IsAnagram(string s, string t) { //My version: //if (s.Length != t.Length) // return false; //var dict1 = GetDict(s); //var dict2 = GetDict(t); //foreach (var keyVal in dict1) // if (!dict2.ContainsKey(keyVal.Key) || dict2[keyVal.Key] != keyVal.Value) // return false; //return true; //Dictionary<char, int> GetDict(string str) //{ // var dict = new Dictionary<char, int>(); // foreach (var ch in str) // { // if (dict.ContainsKey(ch)) // dict[ch]++; // else dict.Add(ch, 1); // } // return dict; //} //My implementation (idea not mine) if (s.Length != t.Length) { return(false); } char[] arr = new char[26]; for (int i = 0; i < s.Length; i++) { arr[s[i] - 'a']++; arr[t[i] - 'a']--; } return(arr.All(c => c == 0)); }
private static char CheckCols(char[,] field) { for (int col = 0; col < 3; ++col) { char[] curr = new char[3]; for (int row = 0; row < 3; ++row) { curr[row] = field[row, col]; } if (curr.All(sign => sign == curr[0])) { return(curr[0]); } } return('-'); }
private static char CheckDiags(char[,] field) { char[] mainDiag = new char[3]; FindMainDiag(mainDiag, field); if (mainDiag.All(sign => sign == mainDiag[0])) { return(mainDiag[0]); } char[] subDiag = new char[3]; FindSubDiag(subDiag, field); if (subDiag.All(sign => sign == subDiag[0])) { return(subDiag[0]); } return('-'); }
public static void Main() { string str = "abbhdwsy"; int append = 0; char[] result = new char[8]; while (!result.All(c => c != '\0')) { string temp = CalculateMD5Hash(str + (++append)); if (temp.Substring(0, 5).All(c => c == '0')) { int num = Convert.ToInt32(temp[5].ToString(), 16); if (num < 8 && result[num] == '\0') { result[num] = temp[6]; } } } Console.WriteLine(result); }
static void Main(String[] args) { var n = Convert.ToInt32(Console.ReadLine()); var firstStone = Console.ReadLine().ToCharArray(); var stones = new char[n - 1][]; for (var i = 0; i < n - 1; i++) { stones[i] = Console.ReadLine().ToCharArray(); } var gemStones = new HashSet <char>(); foreach (var baseGem in firstStone.Where(baseGem => stones.All(stone => stone.Contains(baseGem)))) { gemStones.Add(baseGem); } Console.WriteLine(gemStones.Count); }
/// <summary> /// Check how the user guess matches <see cref="Code"/>. /// </summary> /// <param name="input">User's input.</param> public void CheckCode(string input) { char[] userColors = input.ToCharArray(); char[] code = Code.ToCharArray(); char[] answer = new char[CodeLength]; for (int index = 0; index < CodeLength; index++) { if (userColors[index] == code[index]) { answer[index] = Answers.CORRECT_ANSWER; } else if (code.Contains(userColors[index])) { answer[index] = Answers.COLOR_EXISTS; } else { answer[index] = Answers.WRONG_GUESS; } } Round++; if (answer.All(c => c == Answers.CORRECT_ANSWER)) { Status = GameStatus.Won; User.GamesWon++; } if (Round >= TimeLimit) { Status = GameStatus.Lost; User.GamesLost++; } string output = RandomizeArray(answer); User.SaveRound(userColors, output.ToCharArray()); }
public void IsStandardPunctuationChar_Punctuation_ReturnsTrue() { // Arrange var punctuations = new char[] { '!', '"', '#', '%', '&', '\'', '(', ')', '*', ',', '-', '.', '/', ':', ';', '?', '@', '[', '\\', ']', '{', '}', '|', '`', }; // Act var correct = punctuations.All(LexingHelper.IsStandardPunctuationChar); // Assert Assert.That(correct, Is.True); }
static void VvodDvumerniiArray(ref int stringSize, ref int columnSize, ref char[,] dvumernii_array) { Console.Write("\nВведите количество столбцов: "); columnSize = Search_for_Bugs.ProverkaVvoda(); dvumernii_array = new char[stringSize, columnSize]; Random rand = new Random(); for (int i = 0; i < stringSize; i++) { Console.WriteLine("Вводдля строки №" + i); for (int j = 0; j < columnSize; j++) { dvumernii_array[i, j] = Search_for_Bugs.Trying(); } } Dictionary <int, char[]> tempDict = new Dictionary <int, char[]>(); char[] tempArr = new char[columnSize]; for (int i = 0; i < stringSize; i++) { for (int j = 0; j < columnSize; j++) { tempArr[j] = dvumernii_array[i, j]; } if (!tempArr.All(char.IsLetter)) { tempDict.Add(i, tempArr); tempArr = new char[columnSize]; } } Console.WriteLine("------------------Массив-----------------\n"); for (int i = 0; i < dvumernii_array.GetLength(0); i++) { for (int j = 0; j < dvumernii_array.GetLength(1); j++) { Console.Write("{0}\t", dvumernii_array[i, j]); } Console.WriteLine(); } Console.WriteLine("\n-----------------------------------------"); if (tempDict.Count > 0) { Console.WriteLine("---------------Новый массив--------------\n"); if (dvumernii_array.GetLength(0) == tempArr.Length) { Console.WriteLine(" Нет строк без цифр "); } else { foreach (var item in tempDict) { foreach (var ar in item.Value) { Console.Write("{0}\t", ar); } Console.WriteLine(); } } do { Console.WriteLine("\n------------------------------"); Console.WriteLine("| Выберите вид массива: |"); Console.WriteLine("| 1) Повторить удаление |"); Console.WriteLine("| 9) Вернуться в начало |"); Console.WriteLine("| 0) Выход из консоли |"); Console.WriteLine("------------------------------"); Console.Write("Действие: "); int check = Search_for_Bugs.ProverkaVvoda(); switch (check) { case 1: Console.WriteLine(" "); Console.WriteLine("Больше нет строк без цифр"); Console.WriteLine(" "); break; case 9: Main(); break; case 0: Environment.Exit(0); //Выход из консоли break; default: Text_Dialog.PrintErrorMenu(); continue; } } while (!true); } else { Console.WriteLine("Массив пуст"); } }