알고리즘/알고리즘 기초 100제
-
문제 24 - 평균보다 점수가 넘은 학생들의 비율알고리즘/알고리즘 기초 100제 2020. 10. 19. 00:18
// print avg // input : 7 100 95 90 80 70 60 50 // output : 57.143% import java.util.*; /* javac Youtube24.java -encoding UTF-8 평균보다 점수가 넘은 학생들의 비율. */ class Youtube24 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println("Input the number of students"); int students = sc.nextInt(); int[] scores = new int[students]; int sum = 0; for(int i=0; i
-
문제 25 - N의 사이클 길이 구하기알고리즘/알고리즘 기초 100제 2020. 10. 19. 00:17
문제 N이 주어졌을때 N의 사이클의 길이를 구하시오(126 2+6=8 -> 68 6+8=14->84 8+4=12 -> 42 4+2=6 26 = 4번 class Youtube25 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int count = 0; int num = sc.nextInt(); int tempNum = num; int temp = 0; do{ temp = tempNum/10 + tempNum %10; tempNum = tempNum%10 * 10 + (temp %10); count++; }while(tempNum!=num); System.out.println(count); } }
-
문제 23번 - 문자열 거꾸로 출력.알고리즘/알고리즘 기초 100제 2020. 9. 21. 11:30
문제 : 입력된 문자열 거꾸로 출력하기 예) ADEFH -> HFEDA import java.util.*; class Youtube23 { public static void main(String[] args){ String checkStr = new Scanner(System.in).next(); String reverseStr = new StringBuffer(checkStr).reverse().toString(); System.out.println(reverseStr); /* 강의 정답. String n = "ADEFH"; char str[] = n.toCharArray(); char tmp; int len = str.length; for(int i=0; i
-
문제 22번 - 팬린드롬알고리즘/알고리즘 기초 100제 2020. 9. 21. 11:29
문제 : 팬린드롬인지 판별 * 팬린드롬 : 거꾸로 읽어도 같은 문장 예) 12321 -> true import java.util.*; class Youtube22 { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int num = sc.nextInt(); String parseNum = String.valueOf(num); String reverseStr = new StringBuffer(parseNum).reverse().toString(); if(parseNum.equals(reverseStr)){ System.out.println(true); }else{ System.out.println(false); } /..
-
문제 21번 - 중복된 수 제거 후 출력알고리즘/알고리즘 기초 100제 2020. 9. 21. 11:25
import java.util.*; public class Youtube21 { public static void main(String[] args){ /* List resultList = new ArrayList(); System.out.println("if you stop program, input 0"); Scanner scanner = new Scanner(System.in); while(true){ int number = scanner.nextInt(); if(number == 0){ for(int result : resultList){ System.out.print(result + " "); } break; } if(1
-
문제 19 - 거듭제곱 출력알고리즘/알고리즘 기초 100제 2020. 8. 20. 10:32
문제 : 5,3 입력시 5의 3승, = 125 출력. import java.util.*; public class Youtube19 { /* n^m 5^3 = 5*5*5 = 125 */ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); System.out.print("Input the n : "); int n = scanner.nextInt(); System.out.print("Input the m : "); int m = scanner.nextInt(); int result = 1; for(int i=1; i
-
문제18 - 별출력알고리즘/알고리즘 기초 100제 2020. 8. 20. 10:27
문제 : 5입력시 아래와 같이 출력 * ** *** **** ***** import java.util.*; public class Youtube18 { /* n=5 * ** *** **** ***** */ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); System.out.print("Input the number : "); int n = scanner.nextInt(); for(int i=1; i0; j--){ if(j>i){ System.out.print(" "); }else{ System.out.print("*"); } } System.out.println(); } } } 강의정답 for(int i=0..