// Java package package1; import java.util.Scanner; public class Program { public static void main(String[] args) { try (Scanner sc = new Scanner(System.in)) { int number = sc.nextInt(); String binary = Integer.toBinaryString(number); System.out.println(binary); } catch (Exception ex) { System.err.println(ex.getMessage()); } }}
// C# using System; namespace ToBinary{ class Program { static void Main(string[] args) { string input = Console.ReadLine(); int number = Convert.ToInt32(input); string binary = Convert.ToString(number, 2); Console.WriteLine(binary); } }}
// C/C++ // [VC] suppress error messages about obsolete & deprecated functions#pragma warning(disable : 4996)#define _CRT_SECURE_NO_WARNINGS#define _CRT_SECURE_NO_WARNINGS_GLOBALS #include #include #define LENGTH 11 int main(int argc, char **argv){ char buffer[LENGTH]; int number = 0; do { fgets(buffer, LENGTH, stdin); number = atoi(buffer); } while (number < 0); printf("%12s %d\n", "Integer", n..
https://www.hackerrank.com/challenges/coin-change/problem def get_ways(n, c): return [[]] if n == 0 else [[b, *j] for i, b in enumerate(c) if b = coin: for way in get_ways(change - coin, coins[i:]): my_ways.append([coin, *way]) return my_ways n = int(input("Target Change: ").strip())c = list(map(int, input("Coin List: ").strip().split()))c.sort()ways = get_ways(n, c)print("Number of Ways:", len(..
https://www.hackerrank.com/challenges/reduced-string/problem # Python 3 def reduce_string(s): for i, x in enumerate(s[1:]): if s[i] == x: return reduce_string(s[:i] + s[i + 2:]) return s result = reduce_string(input().strip())print(result) if result != '' else print('Empty String') # Python 3 def reduce_string(s): str_list = list(s) index = 0 while len(str_list) > 1 and index < len(str_list) - 1..
https://projecteuler.net/problem=3 from typing import List def is_prime(my_target: int, my_primes: List[int]) -> bool: for prime in my_primes: if my_target % prime == 0: return False return True def get_primes(my_target: int) -> List[int]: my_primes: List[int] = [] for number in range(2, my_target + 1): if is_prime(number, my_primes): my_primes.append(number) return my_primes def get_factors(my_..
https://projecteuler.net/problem=2 def f(n): return n if n[-1] + n[-2] >= 4000000 else f(n + [n[-1] + n[-2]]) print(sum([i for i in f([1, 2]) if i % 2 == 0])) # Python 3 fibonacci = [1, 2]a = 1b = 2c = 3 while c < 4000000: fibonacci.append(c) a = b b = c c = a + b total = 0 for i in fibonacci: if i % 2 == 0: total += i print(total) # Python 3 fibonacci = [1, 2]total = 2c = 3 while c < 4000000: f..
참고 :https://www.nayuki.io/page/project-euler-solutionshttps://projecteuler.net/problem=1 # Python 3 total: int = 0 for i in range(1, 1000): if i % 3 == 0 or i % 5 == 0: total += i print("total =", total) # Python 3 print(sum([i for i in range(1, 1000) if i % 3 == 0 or i % 5 == 0])) // C/C++ #include #include #include #include int _tmain(INT32 argc, LPTSTR argv[]) { INT32 total = 0; for (INT32 i ..
import sys # virtualenv if hasattr(sys, 'real_prefix') \ and hasattr(sys, 'base_prefix') \ and hasattr(sys, 'prefix') \ and sys.base_prefix == sys.prefix: print("in virtualenv environment") print("sys.real_prefix", sys.real_prefix) print("sys.base_prefix", sys.base_prefix) print("sys.prefix ", sys.prefix) # venv if not hasattr(sys, 'real_prefix') \ and hasattr(sys, 'base_prefix') \ and hasattr(s..