160 lines
4.3 KiB
C#
160 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.IO;
|
|
using System.Security.Permissions;
|
|
|
|
namespace ConsoleApp1
|
|
{
|
|
internal class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
DataRead();
|
|
|
|
int num = Feladat3();
|
|
Console.WriteLine(num);
|
|
|
|
|
|
int nepsuruseg = Feladat4();
|
|
Console.WriteLine(nepsuruseg);
|
|
|
|
int kinatobbmintindiaaaaa = Feladat5();
|
|
Console.WriteLine(kinatobbmintindiaaaaa);
|
|
|
|
string harmadik = Feladat6();
|
|
Console.WriteLine(harmadik);
|
|
|
|
Feladat7();
|
|
|
|
Console.ReadLine();
|
|
}
|
|
|
|
public static void DataRead()
|
|
{
|
|
string path = "adatok-utf8.txt";
|
|
FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
|
StreamReader streamReader = new StreamReader(fileStream);
|
|
|
|
string line = streamReader.ReadLine();
|
|
line = streamReader.ReadLine();
|
|
|
|
while (line != null)
|
|
{
|
|
string[] datas = line.Split(';');
|
|
string orszagnev = datas[0];
|
|
int terulet = Convert.ToInt32(datas[1]);
|
|
string nepesseg = datas[2];
|
|
|
|
int Nepesseg;
|
|
bool IsNumber = Int32.TryParse(nepesseg, out Nepesseg);
|
|
if (!IsNumber)
|
|
{
|
|
string asd = nepesseg.Replace("g", "0000");
|
|
Nepesseg = Convert.ToInt32(asd);
|
|
}
|
|
|
|
int fovarosNepesseg = Convert.ToInt32(datas[4]);
|
|
|
|
Orszag orszag = new Orszag(orszagnev, terulet, Nepesseg, datas[3], fovarosNepesseg);
|
|
|
|
Data.orszagok.Add(orszag);
|
|
|
|
line = streamReader.ReadLine();
|
|
}
|
|
|
|
streamReader.Close();
|
|
fileStream.Close();
|
|
}
|
|
|
|
|
|
public static int Feladat3()
|
|
{
|
|
return Data.orszagok.Count;
|
|
}
|
|
|
|
public static int FindCountry(string country) {
|
|
int i = 0;
|
|
while (Data.orszagok[i].Orszagnev != country && i <= Data.orszagok.Count)
|
|
{
|
|
i++;
|
|
}
|
|
|
|
return i;
|
|
}
|
|
public static int Feladat4() {
|
|
int a = FindCountry("Kína");
|
|
|
|
return Data.orszagok[a].Nepesseg / Data.orszagok[a].Terulet;
|
|
}
|
|
|
|
public static int Feladat5() {
|
|
int india = FindCountry("India");
|
|
int kina = FindCountry("Kína");
|
|
|
|
return Data.orszagok[kina].Nepesseg - Data.orszagok[india].Nepesseg;
|
|
}
|
|
|
|
public static string Feladat6()
|
|
{
|
|
List<Orszag> asd = Data.orszagok.OrderBy(x => x.Nepesseg).ToList();
|
|
|
|
return asd[asd.Count - 3].Orszagnev;
|
|
}
|
|
|
|
|
|
public static void Feladat7()
|
|
{
|
|
foreach (var item in Data.orszagok)
|
|
{
|
|
if (item.FovarosiKoncentracio)
|
|
{
|
|
Console.WriteLine($"{item.Orszagnev}, {item.Fovaros}");
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public static class Data
|
|
{
|
|
public static List<Orszag> orszagok = new List<Orszag>();
|
|
}
|
|
public class Orszag
|
|
{
|
|
public string Orszagnev { get; private set; }
|
|
public int Terulet { get; private set; }
|
|
public int Nepesseg { get; private set; }
|
|
public string Fovaros { get; private set; }
|
|
public int FovarosNepesseg { get; private set; }
|
|
public bool FovarosiKoncentracio { get; private set; }
|
|
|
|
public Orszag(string orszagnev, int terulet, int nepesseg, string fovaros, int fovarosNepesseg)
|
|
{
|
|
Orszagnev = orszagnev;
|
|
Terulet = terulet;
|
|
Nepesseg = nepesseg;
|
|
Fovaros = fovaros;
|
|
FovarosNepesseg = fovarosNepesseg * 1000;
|
|
|
|
FovarosiKoncentracio = KoncentraltFovaros(FovarosNepesseg, Nepesseg);
|
|
}
|
|
|
|
public bool KoncentraltFovaros(int fovarosNepesseg, int nepesseg)
|
|
{
|
|
if (fovarosNepesseg >= nepesseg * 0.3)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|