diff --git a/challenge-1/submissions/VadimihrSvS/solution-template.go b/challenge-1/submissions/VadimihrSvS/solution-template.go new file mode 100644 index 0000000..ad02c04 --- /dev/null +++ b/challenge-1/submissions/VadimihrSvS/solution-template.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" +) + +func main() { + var a, b int + // Read two integers from standard input + _, err := fmt.Scanf("%d, %d", &a, &b) + if err != nil { + fmt.Println("Error reading input:", err) + return + } + + // Call the Sum function and print the result + result := Sum(a, b) + fmt.Println(result) +} + +// Sum returns the sum of a and b. +func Sum(a int, b int) int { + // TODO: Implement the function + return a + b +} diff --git a/challenge-2/submissions/VadimihrSvS/solution-template.go b/challenge-2/submissions/VadimihrSvS/solution-template.go new file mode 100644 index 0000000..2962812 --- /dev/null +++ b/challenge-2/submissions/VadimihrSvS/solution-template.go @@ -0,0 +1,31 @@ +package main + +import ( + "bufio" + "fmt" + "os" +) + +func main() { + // Read input from standard input + scanner := bufio.NewScanner(os.Stdin) + if scanner.Scan() { + input := scanner.Text() + + // Call the ReverseString function + output := ReverseString(input) + + // Print the result + fmt.Println(output) + } +} + +// ReverseString returns the reversed string of s. +func ReverseString(s string) string { + // TODO: Implement the function + runes := []rune(s) + for i, j := 0, len(runes) - 1; i < j; i, j = i + 1, j - 1{ + runes[i], runes[j] = runes[j], runes[i] + } + return string(runes) +} diff --git a/challenge-3/submissions/VadimihrSvS/solution-template.go b/challenge-3/submissions/VadimihrSvS/solution-template.go new file mode 100644 index 0000000..41879bd --- /dev/null +++ b/challenge-3/submissions/VadimihrSvS/solution-template.go @@ -0,0 +1,71 @@ +package main + +import "fmt" + +type Employee struct { + ID int + Name string + Age int + Salary float64 +} + +type Manager struct { + Employees []Employee +} + +// AddEmployee adds a new employee to the manager's list. +func (m *Manager) AddEmployee(e Employee) { + // TODO: Implement this method + m.Employees = append(m.Employees, e) +} + +// RemoveEmployee removes an employee by ID from the manager's list. +func (m *Manager) RemoveEmployee(id int) { + // TODO: Implement this method + for i, e := range m.Employees { + if e.ID == id { + m.Employees = append(m.Employees[:i], m.Employees[i+1:]...) + break + } + } + +} + +// GetAverageSalary calculates the average salary of all employees. +func (m *Manager) GetAverageSalary() float64 { + // TODO: Implement this method + var result float64 + for _, e := range m.Employees { + result += e.Salary + } + if len(m.Employees) != 0 { + return result / float64(len(m.Employees)) + } else { + return 0.0 + } +} + +// FindEmployeeByID finds and returns an employee by their ID. +func (m *Manager) FindEmployeeByID(id int) *Employee { + // TODO: Implement this method + for _, e := range m.Employees { + if e.ID == id { + return &e + } + } + return nil +} + +func main() { + manager := Manager{} + manager.AddEmployee(Employee{ID: 1, Name: "Alice", Age: 30, Salary: 70000}) + manager.AddEmployee(Employee{ID: 2, Name: "Bob", Age: 25, Salary: 65000}) + manager.RemoveEmployee(1) + averageSalary := manager.GetAverageSalary() + employee := manager.FindEmployeeByID(2) + + fmt.Printf("Average Salary: %f\n", averageSalary) + if employee != nil { + fmt.Printf("Employee found: %+v\n", *employee) + } +}