목록CSE/baekjoon & swexpert (53)
한 걸음 두 걸음
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { String getStr = sc.nextLine(); StringBuilder result = new StringBuilder(""); result.append(getStr.charAt(0)); for(int i = 1; i < getStr.length(); i++ ) { if(getStr.charAt(i)=='-') result.append(getStr.charAt(i+1)); } System.out.println(result); break; } } }
StringBuffer에 있는 reverse()함수를 사용하여 뒤집어준 뒤, toString으로 문자열변환시켜주었습니다. import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); while(true) { String getStr = sc.nextLine(); if(getStr.equals("END")) break; else System.out.println(new StringBuffer(getStr).reverse().toString()); } } } 여기서 문자열 비교를 통해 END를 찾아낼 때 getStr == "END"로 하면 안돼서 getStr...
//int hi[] 인트형배열 Arrays.sort(hi); // 오름차순으로 정렬! -> 모든 배열 정렬 Arrays.sort(hi, 1, 3) // -> index = 1~3인곳만 정렬 Arrays.sort(hi, Collections.reverseOrder()); // 내림차순으로 정렬 문자열로 바꿔주기 Arrays.toString(hi) 참고URL https://jamesdreaming.tistory.com/162 import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int appleNum = sc.nextInt(); int birdLengt..
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); // 몇 개의 테스트케이스를 받을 것인지 입력 int testCase = sc.nextInt(); //테스트케이스만큼 변수 생성 int num[] = new int [testCase]; String content[] = new String[testCase]; //결과값 들어갈 문자열 String result = ""; //테스트케이스만큼 입력받습니다. for(int i = 0; i < testCase; i++) { result = ""; num[i] = sc.nextInt(); //System.o..
문제 정수를 저장하는 스택을 구현한 다음, 입력으로 주어지는 명령을 처리하는 프로그램을 작성하시오. 명령은 총 다섯 가지이다. push X: 정수 X를 스택에 넣는 연산이다. pop: 스택에서 가장 위에 있는 정수를 빼고, 그 수를 출력한다. 만약 스택에 들어있는 정수가 없는 경우에는 -1을 출력한다. size: 스택에 들어있는 정수의 개수를 출력한다. empty: 스택이 비어있으면 1, 아니면 0을 출력한다. top: 스택의 가장 위에 있는 정수를 출력한다. 만약 스택에 들어있는 정수가 없는 경우에는 -1을 출력한다. java.util.stack에서 제공하는 라이브러리를 활용하여 문제를 풀었다. 스택 자료구조는 import java.util.stack;에 있고 이는 java documentation에 ..