← 목록

Synth · CodeAlpaca일부

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

[output] | def get_next(mylist): for i in range(len(mylist)-1): return mylist[i+1] print(get_next(mylist)) [instruction] | Program a function to get the next element of a list. [input] | mylist = [1,3,5,7]

[output] | def join_strings(s1, s2): return s1 + s2 [instruction] | Write a function that takes in two strings(s1, s2) and returns a string. The output should be "s1s2". [input] |

[output] | SELECT COUNT(*) FROM employees WHERE department_id = <id>; [instruction] | Write a SQL query to find out how many employees work in a department with a certain id. [input] |

[output] | def sub_array(array, num): for i in range(len(array) - 1, 0, -1): if array[i] == num: del array[i] else: break [instruction] | Debug the following piece of code so that the program functions properly. [input] | def sub_array(array, num): for i in range(len(array) - 1, 0, -1): if array[i] == num: del array[i]

[output] | def LCSubStr(Str1, Str2): n = len(Str1) m = len(Str2) LCSuff = [0] * (n + 1) LCSuff = [[0 for k in range(m + 1)] for l in range(n + 1)] result = 0 for i in range(n): for j in range(m): if (Str1[i] == Str2[j]): LCSuff[i + 1][j + [instruction] | Create an algorithm to find out the longest common sub-sequence between two string inputs. [input] | "AGGTAB" "GXTXAYB"

[output] | def filter_length(arr, th): subset = [] for el in arr: if len(el) <= th: subset.append(el) return subset [instruction] | Create a function to return the subset of an array which has the lengths of its elements smaller than the given threshold. [input] | [1, 5, 2, 8], threshold = 5

[output] | NSLog(@"Hello World!"); [instruction] | Write an Objective-C code snippet to print the phrase "Hello World!" to the terminal/console. [input] |

[output] | System.out.println(num); [instruction] | Write a Java code snippet to print out the value of the variable "num" to the console. [input] | int num = 10;

[output] | public String replaceVowels(String s) { String result = ""; for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { result += "*"; } else { result += ch; } } [instruction] | Create a Java method that takes a string and returns the same string with all vowels replaced by asterisks (ie. "Hello" should return "H*ll*"). [input] | String s = "Hello";

[output] | #include <iostream> // Function to calculate the // nth Fibonacci number int calcFib(int n) { if (n <= 1) return n; return calcFib(n - 1) + calcFib(n - 2); } // Test Harness to verify the correctness // of the calcFib implementation int main() { // Input value to calculate const int n [instruction] | Create a test harness in C++ to verify the correctness of the following function [input] | // A function to calculate the nth Fibonacci number // Input: nth Fibonacci number // Output: nth Fibonacci number int calcFib(int n) { if (n<=1) return n; return calcFib(n-1) + calcFib(n-2); }

[output] | function rotateArray(arr, n) { while (n > 0) { let temp = arr[arr.length-1]; for (let i = arr.length-2; i >= 0; i--) { arr[i+1] = arr[i]; } arr[0] = temp; n--; } return arr; } [instruction] | Write a JavaScript program to rotate an array by a given number [input] | let arr = [1, 2, 3, 4, 5]; let n = 2;

[output] | import itertools # Function to generate # n permutations of the given array def permutation(arr, n): # Get all permutations permList = list(itertools.permutations(arr, n)) # Converting each tuple in the # list of tuples to list res = [list(ele) for ele in permList] # Returning t [instruction] | Create a function in Python to generate n permutations of a given array. [input] | arr = [1, 2, 3] n = 6

[output] | SELECT MIN(salary) FROM employees; [instruction] | Write an SQL query to find the minimum salary among all employees [input] |

[output] | .block-level { display: block; } [instruction] | Create a CSS class to display an element as a block-level element. [input] |

[output] | class Car: def __init__(self, make, model): self.make = make self.model = model [instruction] | Create a python class "Car" with fields "make" and "model". [input] |

[output] | const colors = ["red", "blue", "green"]; [instruction] | Create an array of three strings: "red", "blue", and "green". [input] |

[output] | def flatten_2d_array(arr): flat_arr = [] for subarr in arr: flat_arr += subarr return flat_arr # Driver code input_list = [[1, 2], [3, 4]] print(flatten_2d_array(input_list)) [instruction] | Generate a Python code that flattens a two-dimensional array. [input] | [[1, 2], [3, 4]]

[output] | #include <stdio.h> int main() { // Declare vars int n, largest; // Read input scanf("%d", &n); // Initialize largest largest = n; // Iterate over other elements while (n > 0) { scanf("%d", &n); // Update largest if (n > largest){ largest = n; } } // Print [instruction] | Write a C program which reads numbers until 0 is entered and prints the largest number [input] |

[output] | def concat_strings(a, b): print(a + b) concat_strings("Hello ", "world!") [instruction] | Create a function that concatenates two strings and prints them out. [input] | a = "Hello " b = "world!"

[output] | for(int i = 0; i <= 10; i++){ if(i % 2 == 0){ System.out.println(i); } } [instruction] | Write a for loop in Java that prints out the even numbers between 0 and 10. [input] |

[output] | def print_longest_string(strings): longest_string = "" for string in strings: if len(string) > len(longest_string): longest_string = string print(longest_string) print_longest_string(strings) [instruction] | Implement a function in Python that takes a list of strings as parameter and prints out the longest string. [input] | strings = ["Hello", "world", "Welcome","to", "my", "programming", "challenge"]

[output] | function bubbleSort(arr) { let swapped; do { swapped = false; for (let i=0; i < arr.length; i++) { if (arr[i] && arr[i + 1] && arr[i] > arr[i + 1]) { let temp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = temp; swapped = true; } } } while ( [instruction] | Create a function that performs a bubble sort of an array in JavaScript. [input] | arr = [4, 7, 1, 3, 6, 9, 8, 10, 2, 5]

[output] | public static int[] getAllPrimeNumbers(int number){ int[] primeNumbers = new int[number]; int index = 0; for (int i = 2; i <= number; i++){ if(isPrime(i)){ primeNumbers[index] = i; index++; } } return primeNumbers; } public static boolean [instruction] | Write a function in Java that takes an integer and returns an array of all the prime numbers from 2 up to the number. [input] | number = 10

[output] | SELECT * FROM customers WHERE city = "New York" AND age > 30 ORDER BY age ASC; [instruction] | Optimize the runtime of this SQL query. [input] | SELECT * FROM customers WHERE age > 30 AND city == "New York"

[output] | Node* findLCA(Node* root, Node* n1, Node* n2){ if (root == NULL) return NULL; if (root == n1 || root == n2) return root; Node *left_lca = findLCA(root->left, n1, n2); Node *right_lca = findLCA(root->right, n1, n2); if (left_lca && right_lca) return root; return [instruction] | Find the lowest common ancestor in a binary tree in C++. [input] |

[output] | In Java, two strings can be compared using the equals() or compareTo() methods. The equals() method returns true if the two strings have the same length and contain the same characters in the same order. The compareTo() method returns 0 if the two strings have the same length and contain the sam [instruction] | How do you compare two strings in Java? [input] |

[output] | def Fibonacci(n): if n < 0: print("Incorrect input") # First Fibonacci number is 0 elif n == 0: return 0 # Second Fibonacci number is 1 elif n == 1: return 1 else: return Fibonacci(n-1)+Fibonacci(n-2) [instruction] | Using the input, write a function that prints out the Nth Fibonacci number. [input] |

[output] | def getSecondMax(a): s = sorted(a)[-2] print(s) [instruction] | Given a Python function, edit the function such that it correctly prints the second highest value of the list. [input] | def getSecondMax(a): print(max(a))

[output] | r"(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})" [instruction] | Generate a valid regular expression to catch URLs in strings. [input] |

[output] | def sum_elements(X): sums = 0 for i in range(len(X)): for j in range(len(X[i])): sums+=X[i][j] return sums print(sum_elements(X)) [instruction] | Create a Python script to output the sum of the elements in a given 2-D array. [input] | X = [[11, 18], [20, 1], [12, 16]]

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