Last active
July 30, 2018 12:42
-
-
Save dhirabayashi/f751c2e385e57e75f040a38ce72f0290 to your computer and use it in GitHub Desktop.
This file contains hidden or 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.List; | |
public class Alphabet3 { | |
public static void main(String[] args) { | |
final List<Character> LIST = List.of('u', 'd', 'c', 's', 't', 'b'); | |
for(Character c1 : LIST) { | |
for(Character c2 : LIST) { | |
for(Character c3 : LIST) { | |
System.out.println("" + c1 + c2 + c3); | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or 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.HashMap; | |
import java.util.Map; | |
import java.util.Scanner; | |
public class AlphabetN { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int n = scanner.nextInt(); | |
Map<String, String> convertTable = new HashMap<>(); | |
convertTable.put("0", "u"); | |
convertTable.put("1", "d"); | |
convertTable.put("2", "c"); | |
convertTable.put("3", "s"); | |
convertTable.put("4", "t"); | |
convertTable.put("5", "b"); | |
for(int i = 0; i < Math.pow(6, n); i++){ | |
String tmp = leftPaddingZero(convert(i,6),n); | |
StringBuilder sb = new StringBuilder(); | |
for(int j = 0;j < tmp.length(); j++){ | |
sb.append(convertTable.get(tmp.substring(j, j + 1))); | |
} | |
System.out.println(sb); | |
} | |
} | |
private static String convert(int target, int n) { | |
StringBuilder sb = new StringBuilder(); | |
int tmp = target; | |
while (tmp > 0) { | |
sb.append(tmp % n); | |
tmp = (tmp - (tmp % n)) / n; | |
} | |
return sb.reverse().toString(); | |
} | |
private static String leftPaddingZero(String str, int length) { | |
if (str.length() == length) { | |
return str; | |
} else { | |
return leftPaddingZero("0" + str, length); | |
} | |
} | |
} |
This file contains hidden or 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 Main { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int a = scanner.nextInt(); | |
int b = scanner.nextInt(); | |
int c = scanner.nextInt(); | |
String s = scanner.next(); | |
System.out.println((a + b + c) + " " + s); | |
} | |
} |
This file contains hidden or 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.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Date; | |
import java.util.Scanner; | |
public class MyCalendar { | |
public static void main(String[] args) throws Exception { | |
Scanner scanner = new Scanner(System.in); | |
String strDate = scanner.nextLine(); | |
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM"); | |
Date date = sdf.parse(strDate); | |
Calendar cal = Calendar.getInstance(); | |
cal.setTime(date); | |
int month = cal.get(Calendar.MONTH); | |
System.out.println(strDate); | |
// 月が変わるまで続ける | |
while (cal.get(Calendar.MONTH) == month) { | |
if(isSaturday(cal)) { | |
System.out.printf("[%2d]\n", getDay(cal)); | |
} else if(isSunday(cal)) { | |
System.out.printf(" (%2d)", getDay(cal)); | |
} else { | |
System.out.printf(" %2d", getDay(cal)); | |
} | |
nextDay(cal); | |
} | |
} | |
private static void nextDay(Calendar cal) { | |
// 86400000ミリ秒(ちょうど一日)進める | |
cal.setTime(new Date(cal.getTime().getTime() + 86400000)); | |
} | |
private static boolean isSaturday(Calendar cal) { | |
return cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY; | |
} | |
private static boolean isSunday(Calendar cal) { | |
return cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY; | |
} | |
private static int getDay(Calendar cal) { | |
return cal.get(Calendar.DATE); | |
} | |
} |
This file contains hidden or 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.List; | |
import java.util.Scanner; | |
public class Plural { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int num = scanner.nextInt(); | |
for(int i = 0; i < num; i++) { | |
String word = scanner.next(); | |
if(word.endsWith("s") || word.endsWith("sh") || word.endsWith("ch") || word.endsWith("o") || word.endsWith("x")) { | |
word += "es"; | |
} else if(word.endsWith("f") || word.endsWith("fe")) { | |
word = word.substring(0, word.lastIndexOf("f")) + "ves"; | |
} else if(word.endsWith("y") && !List.of('a', 'i', 'u', 'e', 'o').contains(word.charAt(word.length() - 2))) { | |
word = word.substring(0, word.length() - 1) + "ies"; | |
} else { | |
word += "s"; | |
} | |
System.out.println(word); | |
} | |
} | |
} |
This file contains hidden or 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.HashMap; | |
import java.util.Map; | |
import java.util.Scanner; | |
public class Search { | |
public static void main(String[] args) { | |
Scanner scanner = new Scanner(System.in); | |
int n = scanner.nextInt(); | |
Map<String, String> convertTable = new HashMap<>(); | |
convertTable.put("0", "u"); | |
convertTable.put("1", "d"); | |
convertTable.put("2", "c"); | |
convertTable.put("3", "s"); | |
convertTable.put("4", "t"); | |
convertTable.put("5", "b"); | |
for(int i = 0; i < Math.pow(6, n); i++){ | |
String tmp = leftPaddingZero(convert(i,6),n); | |
StringBuilder sb = new StringBuilder(); | |
for(int j = 0;j < tmp.length(); j++){ | |
sb.append(convertTable.get(tmp.substring(j, j + 1))); | |
} | |
String result = sb.toString(); | |
if(result.contains("uud")) { | |
System.out.println(result); | |
} | |
} | |
} | |
private static String convert(int target, int n) { | |
StringBuilder sb = new StringBuilder(); | |
int tmp = target; | |
while (tmp > 0) { | |
sb.append(tmp % n); | |
tmp = (tmp - (tmp % n)) / n; | |
} | |
return sb.reverse().toString(); | |
} | |
private static String leftPaddingZero(String str, int length) { | |
if (str.length() == length) { | |
return str; | |
} else { | |
return leftPaddingZero("0" + str, length); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment