Created
March 14, 2016 06:45
-
-
Save jianminchen/9d121bd95266db41dfa8 to your computer and use it in GitHub Desktop.
Anagram - start to read more Lambda expression code in C#/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.IO; | |
class Solution | |
{ | |
private static int Find_AnagramCount(string Input) | |
{ | |
int _returnResult = 0; | |
List<char> first_HalfList = new List<char>(Input.Substring(0, Input.Length / 2).ToCharArray().Select(g=>Convert.ToChar(g))) ; | |
List<char> Second_HalfList = new List<char>(Input.Substring(Input.Length / 2).ToCharArray().Select(g => Convert.ToChar(g))); | |
foreach (char currentChar in Second_HalfList) | |
{ | |
first_HalfList.Remove(currentChar); | |
} | |
if (first_HalfList != null && first_HalfList.Count > 1) | |
_returnResult = first_HalfList.Count; | |
return _returnResult; | |
} | |
static void Main(string[] args) | |
{ | |
int t = Convert.ToInt32(Console.ReadLine().Trim()); | |
int[] results = new int[t]; | |
for (int i = 0; i < t; i++) | |
{ | |
string console_input = Console.ReadLine().Trim(); | |
if (console_input.Length % 2 == 0) | |
{ | |
results[i] = Find_AnagramCount(console_input); | |
} | |
else | |
results[i] = -1; | |
} | |
for (int i = 0; i < t; i++) | |
Console.WriteLine(results[i]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment