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
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
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
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 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
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 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
import java.util.Scanner; | |
public class SimilarArrays { | |
public static void main(String[] args) { | |
Scanner sc = new Scanner(System.in); | |
int n = sc.nextInt(); | |
int[] A = new int[n]; | |
for(int i=0; i<n; i++){ | |
A[i] = sc.nextInt(); | |
}; |
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 Factorial { | |
//階乗を求める再帰関数 | |
static int factorial(int n) { | |
if(n==1) { | |
return 1; | |
} | |
return n * factorial(n-1); | |
} |
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 TimeMeasurement { | |
public static void main(String[] args) { | |
long start = System.nanoTime(); | |
// some processing | |
int[] a = {1,2,3,4,4,5,6,7,8,9,10}; | |
for(int i=0; i<a.length; i++){ | |
System.out.println(a[i]); | |
}; |