Last active
August 27, 2016 08:41
-
-
Save guitarrapc/1cec58eeb8af7bd3fa7b0116a363fbb8 to your computer and use it in GitHub Desktop.
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
void Main() | |
{ | |
// Q1. | |
File.ReadLines(@"c:\shellgei\Q1.txt", Encoding.UTF8) | |
.Select(x => string.Join(" ", x.Split().GroupBy(t => t).OrderBy(g => g.Key).Select(g => $"{g.Key}:{g.Count()}"))) | |
.Dump("Q1"); | |
File.ReadLines(@"c:\shellgei\Q2.txt", Encoding.UTF8) | |
.Select(x => string.Join("",x.Select(c => c).Distinct())) | |
.Dump("Q2"); | |
var i = 0; | |
var p = ""; | |
File.ReadLines(@"c:\shellgei\Q3.txt", Encoding.UTF8) | |
.OrderBy(x => x) | |
.Select(x =>Tuple.Create(x, x.Split()[0], x.Split()[1], ++i)) | |
.ToArray() | |
.SelectMany(x => | |
{ | |
if (x.Item4 == 0) | |
{ | |
p = x.Item2; | |
return new [] {"%%", x.Item1}; | |
} | |
else if (x.Item2 != p) | |
{ | |
p = x.Item2; | |
return new [] {"%%", x.Item1}; | |
} | |
else if (x.Item4 == i) | |
{ | |
p = x.Item2; | |
return new [] {x.Item1, "%%"}; | |
} | |
else | |
{ | |
p = x.Item2; | |
return new[] { x.Item1}; | |
} | |
}) | |
.Dump("Q3"); | |
} | |
// Define other methods and classes here |
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
Write-Host "Q1" -ForegroundColor Cyan; | |
cat .\Q1.txt -Encoding UTF8 | % {[string]::Join(" ",($_.Split() | group | sort name | %{"$($_.Name):$($_.Count)"}))} | |
Write-Host "Q2" -ForegroundColor Cyan; | |
cat .\Q2.txt -Encoding utf8 | %{$o=[ordered]@{}}{$in=[char[]]$_;$in|%{if(!$o.Contains($_)){$o.Add($_,$_)}}}{[string]::new($o.Keys)} | |
cat .\Q2.txt -Encoding utf8 | %{[string]::new([System.Linq.Enumerable]::Distinct([char[]]$_))} | |
Write-Host "Q3" -ForegroundColor Cyan; | |
cat .\Q3.txt -Encoding UTF8 | %{$i=$_.Split(" ");[PSCustomObject]@{a=$i[0];b=$i[1]}} | sort a | %{$p="";$o=@()}{if($p -ne $_.a){"%%"};"$($_.a) $($_.b)";$p=$_.a}{"%%"} | |
Write-Host "Q5" -ForegroundColor Cyan | |
echo 4 | %{$i = $_;cat .\Q5.txt -Encoding UTF8 | %{iex $_.Replace('x', $i)}} | |
Write-Host "Q6" -ForegroundColor Cyan | |
cat .\Q6.txt -Encoding UTF8 | %{[char[]]$c=$_;$f=$c | group | sort Count | Select Name -First 1;$_.Replace($f.Name, "玉子")} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment