Skip to content

Instantly share code, notes, and snippets.

@quangnle
Created May 10, 2016 10:26
Show Gist options
  • Save quangnle/4e0384918f1f322a382405d01c286242 to your computer and use it in GitHub Desktop.
Save quangnle/4e0384918f1f322a382405d01c286242 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tuenti4
{
class Program
{
class Combo
{
public string[] Actions { get; set; }
public bool LongSkill { get; set; }
public int FailedTries { get; set; }
}
static List<Combo> _combos = new List<Combo>();
static void Main(string[] args)
{
_combos.Add(new Combo { Actions = "L-LD-D-RD-R-P".Split('-'), LongSkill = true });
_combos.Add(new Combo { Actions = "D-RD-R-P".Split('-')});
_combos.Add(new Combo { Actions = "R-RD-D-LD-L-K".Split('-'), LongSkill = true });
_combos.Add(new Combo { Actions = "D-LD-L-K".Split('-')});
_combos.Add(new Combo { Actions = "R-D-RD-P".Split('-')});
var lines = File.ReadAllLines("submitInput.txt");
var n = Convert.ToInt32(lines[0]);
var result = "";
for (int i = 1; i <= n; i++)
{
var l = lines[i];
result += "Case #" + i.ToString() + ": " + CountAll(l.Split('-')).ToString() + "\n";
}
File.WriteAllText("submitOutput.txt", result);
}
static void Count(string[] tokens, Combo combo)
{
var result = 0;
for (int i = 0; i < tokens.Length; i++)
{
for (int j = 0; j < combo.Actions.Length; j++)
{
if (i + j >= tokens.Length)
{
if (j == combo.Actions.Length - 1)
result++;
break;
}
else
{
if (combo.Actions[j] != tokens[i + j])
{
if (j == combo.Actions.Length - 1)
result++;
break;
}
}
}
}
combo.FailedTries = result;
}
static int CountAll(string[] tokens)
{
for (int i = 0; i < _combos.Count; i++)
{
Count(tokens, _combos[i]);
}
var result = _combos.Sum(c => c.FailedTries) - _combos.Where(c => c.LongSkill).Sum(c => c.FailedTries);
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment