This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class AdditionAndMultiplication { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
int k = sc.nextInt(); | |
sc.close(); | |
int number = 1; | |
for(int i=0; i<n; i++){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Fibonacci { | |
static int fib(int n) { | |
//引数でn=0,1を指定した際は再帰処理を行わず、即座に1を返す | |
if(n<=1) return 1; | |
return fib(n-1) + fib(n-2); | |
} | |
public static void main(String[] args) { | |
System.out.println(fib(0)); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class BinarySearch { | |
static int binarySearch(int[] A, int key) { | |
int left = 0; | |
int right = A.length; | |
while(left < right) { | |
int mid = (left + right)/2; | |
if(A[mid] == key) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class BinarySearch2 { | |
static int binarySearch(int[] A, int key) { | |
int left = 0; | |
int right = A.length; | |
while(left < right) { | |
int mid = (left + right)/2; | |
if(A[mid] == key) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class GoodInterger2 { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
char[] c = sc.next().toCharArray(); | |
sc.close(); | |
for(int i=0; i<c.length; i++){ | |
int j = i; | |
while(j<c.length) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ThePalindrome { | |
public int find(String s) { | |
// 答えの文字数を決定する. 条件は指定しない(無限ループ. returnでの強制終了) | |
for(int i=s.length(); ;i++){ | |
boolean flag = true; | |
for(int j=0; j<s.length(); j++){ | |
if ((i - j - 1) < s.length() && s.charAt(j) != s.charAt(i - j - 1)){ | |
flag = false; | |
break; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
dictionary-comprehension | |
""" | |
# Pythonはdictionary comprehensionもサポートしている | |
# syntax: <variable> = { key:new_value for (key, value) in <dictionary>.items() } | |
grades = {'Nora': 90, 'Lulu': 15, 'Gino': 60} | |
grades | |
# ---> {'Nora': 90, 'Lulu': 15, 'Gino': 60} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# ReLu activation function, which computes the ReLu of a scalar. | |
def rectified_linear_unit(x): | |
""" Returns the ReLU of x, or the maximum between 0 and x. """ | |
return np.maximum(0, x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
swap with tuple | |
""" | |
x, y = 1, 0 | |
# swap with tuple | |
# tmpなどの変数を使わずにワンラインでswapできる | |
(x, y) = (y, x) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Advanced slicing | |
""" | |
# 応用的な使い方1 | |
# third parameterはstep size.この例ではstep size = 2 | |
s = 'Python is Fun!' | |
s[1:12:2] | |
# ---> 'yhni u' |