Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created September 20, 2016 04:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/877ff5d9f0026ed007e55ef7386fd5a9 to your computer and use it in GitHub Desktop.
Save jianminchen/877ff5d9f0026ed007e55ef7386fd5a9 to your computer and use it in GitHub Desktop.
HackerRank Stryker code sprint - study code #5
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {
static void Main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */
int n,b;
string[] _tokens = Console.ReadLine().Split(' ');
n=int.Parse(_tokens[0]);
b=int.Parse(_tokens[1]);
List<Coord> lstC = new List<Coord>();
List<Coord> lstB = new List<Coord>();
List<double> remLst = new List<double>();
Dictionary<int,Coord> d = new Dictionary<int,Coord>();
while(n-- >0)
{
string[] _tokens1 = Console.ReadLine().Split(' ');
var crd = new Coord();
crd.K = int.Parse(_tokens1[0]);
crd.X = double.Parse(_tokens1[1]);
crd.Y = double.Parse(_tokens1[2]);
crd.Z = double.Parse(_tokens1[3]);
d.Add(crd.K,crd);
lstC.Add(crd);
}
lstC = lstC.OrderByDescending(x=>x.Z).ToList();
for(int i=0;i<b;i++)
{
lstB.Add(lstC[i]);
}
lstC.RemoveRange(0,b);
int ptrC = 0;
var ipq =Console.ReadLine();
while(ipq!=null)
{
string[] q = ipq.Split(' ');
switch(q[0][0])
{
case 'F':
case 'f':
var k = int.Parse(q[1]);
Coord _c = d[k];
if(_c==null||(lstB[0].Z<_c.Z||_c.Z<lstB[lstB.Count-1].Z))
{
Console.WriteLine("Point doesn't exist in the bucket.");
}
else
{
Console.WriteLine("{0} = ({1},{2:3X},{3:3X})",_c.K,_c.X.ToString("N3"),_c.Y.ToString("N3"),_c.Z.ToString("N3"));
}
break;
case 'r':
case 'R':
var k1 = int.Parse(q[1]);
Coord _c1 = d[k1];
if(_c1==null||(lstB[0].Z<_c1.Z||_c1.Z<lstB[lstB.Count-1].Z))
{
Console.WriteLine("Point doesn't exist in the bucket.");
}
else
{
if(ptrC<lstC.Count)
{
// lstB.Remove(_c1);
d[k1]=null;
// remLst.Add(_c1.Z);
Console.WriteLine("Point id {0} removed.",k1);
lstB.Add(lstC[ptrC++]);
//lstB = lstB.OrderByDescending(x=>x.Z).ToList();
// lstC.RemoveAt(0);
}
else
{
Console.WriteLine("No more points can be deleted.");
}
}
break;
}
ipq =Console.ReadLine();
}
}
}
class Coord
{
public int K{get;set;}
public double X{get;set;}
public double Y{get;set;}
public double Z{get;set;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment