static void Main(string[] args) { StreamReader read = new StreamReader("In0303.txt"); StreamWriter write = new StreamWriter("Out0303.txt"); List <Edge> EdgeList = new List <Edge>(); string InputLine; int TopNum = 0, EdgeNum = 0, TopCounter = 0; if ((InputLine = read.ReadLine()) != null) { string[] tmp = InputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); TopNum = int.Parse(tmp[0]); EdgeNum = int.Parse(tmp[1]); } while ((InputLine = read.ReadLine()) != null) { TopCounter++; string[] tmp = InputLine.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < tmp.Length; i++) { Edge edge = new Edge(); edge.top1 = TopCounter; edge.top2 = int.Parse(tmp[i++]); edge.weight = int.Parse(tmp[i]); EdgeList.Add(edge); } } KruskalAlgorithm algor = new KruskalAlgorithm(); algor.Answer(TopNum, EdgeNum, EdgeList, write); read.Close(); write.Close(); }
public List <Point> Parse() { try { List <Point> Outcome = new List <Point>(); using (StreamReader StreamReader = new StreamReader(Filepath)) { string InputLine; string[] FormatInput = new string [2]; double X, Y; while ((InputLine = StreamReader.ReadLine()) != null) { FormatInput = InputLine.Split(','); if (FormatInput.Length == 2) { Double.TryParse(FormatInput[0], out X); Double.TryParse(FormatInput[1], out Y); Outcome.Add(new Point(X, Y)); } } } return(Outcome); } catch (Exception CaughtException) { Console.WriteLine("The file could not be read:"); Console.WriteLine(CaughtException.Message); return(new List <Point>()); } }
public Day4() { var input = InputLine.Split('-').Ints().ToArray(); Lower = input[0]; Upper = input[1]; Part = 2; }
public Tree <int[]> GetTree() { var input = InputLine.Split(' ').Ints().ToArray(); var tree = new Tree <int[]>(); (int, int) Read(int[] data, int start) { var beginning = start; var node = tree.NewNode(); var children = data[start]; var meta = data[start + 1]; start += 2; for (var i = 0; i < children; i++) { var(length, id) = Read(data, start); start += length; node.LinkTo(tree[id]); } node.Value = data[start..(start + meta)]; return(start + meta - beginning, node.Id); }
public static void Main() { List <Student> students = new List <Student>(); string InputLine; while ((InputLine = Console.ReadLine()) != "end of dates") { Student student = students.FirstOrDefault(name => name.Name == InputLine.Split(' ')[0]); if (student == null) { student = new Student(InputLine.Split(' ')[0]); students.Add(student); } student.Dates.AddRange(InputLine.Split(' ', ',') .Skip(1) .Select(date => DateTime.ParseExact(date, "dd/MM/yyyy", CultureInfo.InvariantCulture))); } while ((InputLine = Console.ReadLine()) != "end of comments") { Student student = students.FirstOrDefault(name => name.Name == InputLine.Split('-')[0]); student?.Comments.Add(InputLine.Split('-')[1]); } foreach (var student in students.OrderBy(names => names.Name)) { Console.WriteLine(student.Name); Console.WriteLine("Comments:"); foreach (var comment in student.Comments) { Console.WriteLine($"- {comment}"); } Console.WriteLine("Dates attended:"); foreach (var date in student.Dates.OrderBy(d => d)) { Console.WriteLine($"-- {date.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture)}"); } } }
private async void IRC(DiscordClient ctx) { DiscordChannel TOW_Chat = ctx.GetChannelAsync(valores.tow_chat).Result; DiscordChannel Arena_Chat = ctx.GetChannelAsync(valores.arena_chat).Result; DiscordChannel TDM_Chat = ctx.GetChannelAsync(valores.tdm_chat).Result; DiscordChannel Log = ctx.GetChannelAsync(valores.IdLogWall_E).Result; NetworkStream NS; TcpClient IRC; string InputLine; StreamReader Reader; StreamWriter Writer; try { Console.WriteLine("[IRC] [UBGE-Servidores] [Wall-E] Logando no IRC..."); IRC = new TcpClient(IP, Porta); NS = IRC.GetStream(); Reader = new StreamReader(NS); Writer = new StreamWriter(NS); Writer.WriteLine($"NICK {Nome}"); Writer.Flush(); Writer.WriteLine(Usuario); Console.WriteLine("[IRC] [UBGE-Servidores] [Wall-E] Logado no IRC! Conectando..."); Writer.Flush(); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"[IRC] [UBGE-Servidores] [Wall-E] [Discord] | A conexão com o servidores: \"TOW, Arena, Semanal\" foi estabelecida com sucesso!"); Console.ResetColor(); await Log.SendMessageAsync($"**[IRC] [UBGE-Servidores] [Wall-E] [Discord]** **|** A conexão com o servidores: ``TOW``, ``Arena``, ``Semanal`` foi estabelecida com sucesso! Chat's sendo enviados nos canais: <#{valores.tow_chat}>, <#{valores.arena_chat}> e <#{valores.tdm_chat}>."); while (true) { while ((InputLine = Reader.ReadLine()) != null) { if (InputLine.Contains("PING :port80a.se.quakenet.org") || InputLine.Contains("PING :port80c.se.quakenet.org") || InputLine.Contains("PING :underworld1.no.quakenet.org") || InputLine.Contains("PING :underworld2.no.quakenet.org") || InputLine.Contains("PING :cymru.us.quakenet.org") || InputLine.Contains("PING :dreamhack.se.quakenet.org")) { InputLine.Replace("PING :port80a.se.quakenet.org", ""); InputLine.Replace("PING :port80c.se.quakenet.org", ""); InputLine.Replace("PING :underworld1.no.quakenet.org", ""); InputLine.Replace("PING :underworld2.no.quakenet.org", ""); InputLine.Replace("PING :cymru.us.quakenet.org", ""); InputLine.Replace("PING :dreamhack.se.quakenet.org", ""); } else { if (InputLine.Contains(":[email protected] PRIVMSG #servidores.ubge :")) { await TOW_Chat.SendMessageAsync($"[UBGE-TOW] | ``{DateTime.Now}`` [-] {InputLine.Replace(":[email protected] PRIVMSG #servidores.ubge :", "")}"); } if (InputLine.Contains(":[email protected] PRIVMSG #servidores.ubge :")) { await Arena_Chat.SendMessageAsync($"[UBGE-Arena] | ``{DateTime.Now}`` [-] {InputLine.Replace(":[email protected] PRIVMSG #servidores.ubge :", "")}"); } if (InputLine.Contains(":[email protected] PRIVMSG #servidores.ubge :")) { await TDM_Chat.SendMessageAsync($"[UBGE-TDM] | ``{DateTime.Now}`` [-] {InputLine.Replace(":[email protected] PRIVMSG #servidores.ubge :", "")}"); } } string[] splitInput = InputLine.Split(' '); if (splitInput[0] == "PING") { string Resposta = splitInput[1]; Writer.WriteLine($"PONG {Resposta}"); Writer.Flush(); } switch (splitInput[1]) { case "001": Writer.WriteLine($"JOIN {Canal}"); Writer.WriteLine("auth Wall-E wall-e2018"); Writer.Flush(); break; default: break; } } //Writer.Close(); //Reader.Close(); //IRC.Close(); } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"[IRC] [UBGE-Servidores] [Wall-E] [Discord] | A conexão com o servidores: \"TOW, Arena, Semanal\" não foi estabelecida com sucesso.\n\nErro: {ex.ToString()}"); Console.ResetColor(); await Log.SendMessageAsync($"**[IRC] [UBGE-Servidores] [Wall-E] [Discord]** **|** A conexão com o servidores: ``TOW``, ``Arena``, ``Semanal`` não foi estabelecida com sucesso.\n\n**Erro:**\n```{ex.ToString()}```"); Console.WriteLine("[Wall-E] Reiniciando..."); await ctx.DisconnectAsync(); await Task.Delay(200); await ctx.ConnectAsync(); Console.WriteLine("[Wall-E] Reiniciei."); await Log.SendMessageAsync($"**[IRC] [UBGE-Servidores] [Wall-E] [Discord]** **|** Me auto-reiniciei e o erro foi consertado! Os IRC's estão funcionando novamente e em perfeito estado. Chat's sendo enviados nos canais: <#{valores.tow_chat}>, <#{valores.arena_chat}> e <#{valores.tdm_chat}>.\n\n*(Fatiou, passou, boa 06)*"); Console.WriteLine("[IRC] [Wall-E] Me auto-reiniciei e o erro foi consertado! Os IRC's estão funcionando em perfeito estado."); } }