← 목록

Synth · CodeAlpaca일부

총 20,022개 · 페이지 421/668
🔀 랜덤
불러오는 중…

[output] | #include <iostream> // Function to filter out odd numbers void filter_odd(int arr[], int n) { int i, k; k = 0; // Traversing the given array // from first to last for (i = 0; i < n; i++) { // If arr[i] is even then // store it at current index [instruction] | Generate a C++ code to filter out an array containing odd numbers. [input] |

[output] | def sign_up(username, password): """This function will allow users to sign up for the feature using their username and password.""" # Implement sign up feature # ... if __name__ == '__main__': username = "JohnDoe" password = "Passw0rd" sign_up(username, password) print(" [instruction] | Create a function that allows users to sign up for your feature using their username and password. [input] |

[output] | def filter_even_numbers(arr): """This function takes an array and filters out all even numbers.""" result = [] for num in arr: if num % 2 != 0: result.append(num) return result if __name__ == '__main__': arr = [1, 2, 3, 4, 5, 6, 7, 8, 9] result = filter_e [instruction] | Write a code to filter out all even numbers from an array which contains both even and odd numbers. [input] | arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]

[output] | class ComplexNumber: """This class is used to work with complex numbers.""" def __init__(self, real, imag): self.real = real self.imag = imag def __add__(self, other): """This method overloads the '+' operator to add complex numbers.""" return Co [instruction] | Create a Python class to work with complex numbers. [input] |

[output] | int sum = 0; for(int i = 1; i <= 100; i++) { sum = sum + i; } Console.WriteLine("Sum of all numbers between 1 and 100 = " + sum); [instruction] | Write a loop in C# to calculate the sum of all numbers between 1 and n. [input] | n = 100

[output] | let find = (array, query) => { for (let i = 0; i < array.length; i++) { if (array[i] === query) return i; } return -1; }; let index = find([1, 2, 3, 4, 5], 3); console.log(index); [instruction] | Write a find() method in JavaScript to find an item in an array. [input] | Array: [1, 2, 3, 4, 5], query: 3

[output] | [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4} [instruction] | Write a regular expression pattern to match all email addresses with the same top-level domain. [input] |

[output] | Recursion is a process in which a function calls itself, either directly or indirectly. The execution of such a function consists of recurring steps each of which is called a recurrence step. The number of recurrence steps decreases with each step and the function terminates and returns a result whe [instruction] | Explain how recursion works. [input] |

[output] | <div class="container"></div> [instruction] | Create a div element in HTML with the class "container". [input] |

[output] | int main() { std::cout << "Hello World!" << std::endl; return 0; } [instruction] | In this C++ program, there is an error. Please identify and fix the mistake. [input] | int main() { cout << "Hello World!"; return 0

[output] | def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) [instruction] | Implement a factorial function in Python. [input] |

[output] | <html> <body> <h1>Table showing numbers from 1 to 10</h1> <table> <tr> <th>Number</th> </tr> <tr> <td>1</td> </tr> <tr> <td>2</td> </tr> <tr> <td>3</td> </tr> <tr> <td>4</td> </tr> <tr [instruction] | Make a HTML page that displays a table displaying numbers from 1 to 10. [input] |

[output] | def generate_fibonacci_sequence(length): sequence = [] current_val, next_val = 0,1 for i in range(length): sequence.append(current_val) current_val, next_val = next_val, current_val + next_val return sequence print(generate_fibonacci_sequence(length)) #Output: [0, 1, 1, 2, 3, 5, 8, 13, 21 [instruction] | Generate a Fibonacci sequence with a given length. [input] | length = 10

[output] | class PalindromeChecker: def __init__(self, word): self.word = word def contains_palindrome(self): for i in range(len(self.word)): if self.word[i] == self.word[len(self.word) - 1 - i]: return True return False [instruction] | Create a class that detects if a String contains a palindrome [input] |

[output] | def insert_beginning(my_list, item): my_list = [item] + my_list return my_list [instruction] | Create a function in Python that adds a new item to the beginning of a list. [input] | my_list = ["Cats", "Dogs", "Fish"]

[output] | if (number > 0): print("Welcome to my house") else: print("Goodbye") [instruction] | Write a conditional statement that prints "Welcome to my house" when the user enters a positive number and "Goodbye" when the user enters a negative number. [input] | number = 4

[output] | <p> </p> [instruction] | Write an HTML tag to create a paragraph element. [input] |

[output] | public class Student { String name; String grade; public Student(String name, String grade) { this.name = name; this.grade = grade; } public String getName() { return this.name; } public String getGrade() { return this.grade; } } [instruction] | Design a class in Java to represent a student, with their name and grade fields. [input] |

[output] | single_list = list_1 + list_2 [instruction] | Write a Python code snippet that combines the elements of two lists into a single list. [input] | list_1 = ["Cat", "Dog", "Fish"] list_2 = ["Monkey", "Tiger", "Lion"]

[output] | The best way to design the database is to create three tables: students, tutors and subjects. The students table would contain columns for each student's name, ID and contact details. The tutors table would contain the tutor's name, ID and contact details. The subjects table would contain the subjec [instruction] | You need to design a database for a school where multiple students can have a tutor of a subject. What is the best way to design the database? [input] |

[output] | class SearchSystem: def __init__(self): self.data = {} def add(self, keyword, value): self.data[keyword] = value def search(self, keyword): if keyword in self.data: return self.data[keyword] return None [instruction] | Design a search system in Python with two methods (or functions) one method "add" to add a keyword and value, the other "search" to search by a keyword return the corresponding value. [input] |

[output] | function areaOfTriangle(a, b, c) { let s = (a + b + c) / 2; let area = Math.sqrt(s * (s - a) * (s - b) * (s - c)); return area; } [instruction] | Create a JavaScript program to find the area of a triangle using Heron's formula given the three sides, a, b and c. [input] |

[output] | A possible algorithm is the Euclidean algorithm. It works by repeatedly dividing the larger number by the smaller number and replace the larger number with the remainder until the remainder becomes zero and the last non-zero remainder is the GCD. def gcd(a,b): if a == 0: return b if b == 0: [instruction] | Construct an algorithm to calculate the GCD of two numbers. [input] |

[output] | The web page should have a simple structure with a search bar at the top, followed by a display area where the search results are shown. The search bar should have an input field where the text can be entered and a button to start the search. The algorithm should first detect the text entered in the [instruction] | You need to design a web page with a search bar that returns clickable results. Construct an algorithm to structure the web page. [input] |

[output] | def longest_word(sentence): longest_word = "" words = sentence.split() for word in words: if len(word) > len(longest_word): longest_word = word return longest_word [instruction] | Write a code that takes a sentence as input and prints the longest word in that sentence. [input] | This is a test sentence

[output] | class Dictionary: def __init__(self): self.data = {} def add(self, key, value): self.data[key] = value def find(self, key): if key in self.data: return self.data[key] return None [instruction] | Create a class in Python with methods "add" and "find" to add a value to a dictionary and find the value in it, respectively. [input] |

[output] | def find_closest_pair(points): min_dist = float('inf') closest_pair = None for i in range(len(points)): for j in range(i + 1, len(points)): dist = ((points[i][0] - points[j][0])**2 + (points[i][1] - points[j][1])**2)**0.5 if dist < min_dist: min_dist = dist closest_pair = (points[i], points [instruction] | Write a function to find the closest pair of points in a given array of points. [input] |

[output] | def sort_by_age(employees): sorted_records = [] while employees: record = employees.pop(0) inserted = False for i in range(len(sorted_records)): if record['age'] < sorted_records[i]['age']: sorted_records.insert(i, record) inserted = True break if not inserted: sorted_records.append(recor [instruction] | You have a list of employee records. Each record contains the employee's name, age, salary and department. Write an algorithm to sort the list by age in ascending order. [input] |

[output] | def delete_item(head, item): curr = head prev = None while curr: if curr.val == item: if prev is None: head = curr.next else: prev.next = curr.next return head prev = curr curr = curr.next return head [instruction] | Create a function to delete an item from a linked list given the head and the item. [input] |

[output] | A possible algorithm is to use a recursive approach. The algorithm would start from the beginning of the string and for each character, generate all possible combinations for the rest of the string. Then, for each combination, the character can either be included or excluded from the combination. Fi [instruction] | Construct an algorithm to find all possible combinations of a string of characters. [input] |

← → 방향키로 페이지 이동 · 숫자 입력 후 Enter로 점프