Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- namespace Foci
- {
- class Program
- {
- static void Main(string[] args)
- {
- StreamReader reader = new StreamReader("./meccs.txt");
- List<Game> games = new List<Game>();
- //no need for the first line
- reader.ReadLine();
- //read the rest
- //1. feladat
- while(!reader.EndOfStream)
- {
- string line = reader.ReadLine();
- Console.WriteLine(line);
- games.Add(new Game(line));
- }
- Console.WriteLine("----------------------------------");
- Console.WriteLine("2. feladat:");
- Console.WriteLine("Félidő: ");
- int f = int.Parse(Console.ReadLine());
- Console.WriteLine("Meccsek: ");
- var a = from i in games
- where i.fordulo == f
- select i.player1 + "-" + i.player2 + ": " + i.player1Score + "-" + i.player2Score + " (" + i.player1HalfTimeScore + "-" + i.player2HalfTimeScore + ")";
- foreach (var i in a)
- Console.WriteLine(i);
- Console.WriteLine("----------------------------------");
- Console.WriteLine("3. feladat:");
- a = from i in games
- where (i.player1HalfTimeScore < i.player2HalfTimeScore &&
- i.player1Score > i.player2Score) ||
- (i.player1HalfTimeScore > i.player2HalfTimeScore &&
- i.player1Score < i.player2Score)
- select i.fordulo + " - " + (i.player1Score > i.player2Score ? i.player1:i.player2);
- foreach (var i in a)
- Console.WriteLine(i);
- Console.WriteLine("----------------------------------");
- Console.WriteLine("4. feladat:");
- Console.WriteLine("Csapat név: ");
- string group = Console.ReadLine();
- Console.WriteLine("----------------------------------");
- Console.WriteLine("5. feladat:");
- var teamgames = (from i in games
- where i.player1 == @group || i.player2 == @group
- select i);
- int ScoresMade = teamgames.Sum(i => (i.player1 == group ? i.player1Score : i.player2Score));
- int ScoresGot = teamgames.Sum(i => (i.player1 == group ? i.player2Score : i.player1Score));
- Console.WriteLine("lőtt: " + ScoresMade + "kapott: " + ScoresGot);
- Console.WriteLine("----------------------------------");
- Console.WriteLine("6. feladat:");
- var firstgame = (from i in games
- where i.player1 == @group
- select i).FirstOrDefault();
- Console.WriteLine(firstgame == null ? "A csapat otthon veretlen maradt." : "Forduló: " + firstgame.fordulo + " Csapat: " + firstgame.player2);
- Console.WriteLine("----------------------------------");
- Console.WriteLine("7. feladat:");
- List<int> res = new List<int>();
- for (int i = 0; i < 20; i++)
- {
- var subres = (from item in games
- where (item.player1Score > item.player2Score ? item.player1Score : item.player2Score) == i
- select ((item.player1Score > item.player2Score ? item.player1Score : item.player2Score) , (item.player1Score < item.player2Score ? item.player1Score : item.player2Score))).ToList();
- foreach (var item in subres)
- {
- //res[i] = item.Item1
- }
- }
- Console.ReadLine();
- //Console.WriteLine("Hello World!");
- }
- class Game
- {
- public int fordulo;
- public int player1Score;
- public int player1HalfTimeScore;
- public int player2Score;
- public int player2HalfTimeScore;
- public string player1;
- public string player2;
- public Game(string line)
- {
- var a = line.Split(' ');
- fordulo = int.Parse(a[0]);
- player1Score = int.Parse(a[1]);
- player2Score = int.Parse(a[2]);
- player1HalfTimeScore = int.Parse(a[3]);
- player2HalfTimeScore = int.Parse(a[4]);
- player1 = a[5];
- player2 = a[6];
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment