Skip to content

Instantly share code, notes, and snippets.

@MarcinGladkowski
Last active January 20, 2022 21:23
Show Gist options
  • Save MarcinGladkowski/0428af4d4ab4a444f5f815565243814f to your computer and use it in GitHub Desktop.
Save MarcinGladkowski/0428af4d4ab4a444f5f815565243814f to your computer and use it in GitHub Desktop.
/**
Użycie:
Podaj liczbę wierszy:
2
Podaj imię i nazwisko oddzielone spacją
Marcin Gladkowski
Podaj imię i nazwisko oddzielone spacją
Jan Kowalski
Wpisz szukane nazwisko:
Kowalski
Dla nazwiska Kowalski imię to Jan
*/
using System;
namespace exercise_1
{
class Program
{
static void Main(string[] args)
{
System.Console.WriteLine("Podaj liczbę wierszy: ");
int numbersOfRows = Int32.Parse(Console.ReadLine());
// stworzenie zagniezdzonych tablic,
string[,] Employees = new string[numbersOfRows, 2];
// Podaj imie i nazwisko jednoczesnie: Jan Kowalski
int providedPeople = 0;
while (providedPeople < numbersOfRows) {
System.Console.WriteLine("Podaj imię i nazwisko oddzielone spacją");
string person = Console.ReadLine();
Employees[providedPeople, 0] = person.Split(' ')[0];
Employees[providedPeople, 1] = person.Split(' ')[1];
providedPeople += 1;
}
// // szukanie imienia po nazwisku
System.Console.WriteLine("Wpisz szukane nazwisko: ");
string surname = Console.ReadLine();
for (int i = 0; i < Employees.Length; i++)
{
if(Employees[i, 1] == surname) {
Console.WriteLine($"Dla nazwiska {surname} imię to {Employees[i, 0]}");
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment