import java.util.Scanner;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
StringBuilder str = new StringBuilder();
for(int i=0;i<a.length();i++){
char c = a.charAt(i);
if(Character.isUpperCase(c)){//대문자면
str.append(Character.toLowerCase(c));//소문자로
} else {
str.append(Character.toUpperCase(c));
}
}
System.out.print(str.toString());
}
}
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String a = sc.next();
for (char ch : a.toCharArray())
System.out.println(ch);
}
}
class Solution {
public String solution(String my_string, String overwrite_string, int s) {
return my_string.substring(0,s)
+overwrite_string
+my_string.substring(s+overwrite_string.length());
}
}
class Solution {
public String solution(String str1, String str2) {
StringBuilder sb = new StringBuilder();
int len=str1.length();
for(int i=0;i<len;i++){
sb.append(str1.charAt(i)).append(str2.charAt(i));
}
return sb.toString();
}
}
class Solution {
public String solution(String[] arr) {
String answer = "";
for(String a : arr) {
answer += a;
}
return answer;
}
}
class Solution {
public int solution(int a, int b) {
int answer = 0;
int ab = Integer.parseInt(""+a+b);
int ba = Integer.parseInt(""+b+a);
if(ab>=ba){
answer = ab;
} else {
answer = ba;
}
return answer;
}
}
class Solution {
public int solution(String ineq, String eq, int n, int m) {
boolean answer = false;
if (ineq.equals(">") && eq.equals("="))
answer = n >= m;
else if (ineq.equals("<") && eq.equals("="))
answer = n <= m;
else if (ineq.equals(">") && eq.equals("!"))
answer = n > m;
else
answer = n < m;
return answer ? 1 : 0;
}
}
class Solution {
public int solution(int a, int b, boolean flag) {
if (flag){
return a+b;
} else {
return a-b;
}
}
}
class Solution {
public int solution(int a, int b, int c) {
int answer = 0;
if(a == b && b == c){
answer = 27 * a*a*a*a*a*a;
} else if (a == b || b == c || c == a){
answer = (a+b+c)*(a*a+b*b+c*c);
} else {
answer = a+b+c;
}
return answer;
}
}
class Solution {
public int solution(int a, int b, int c) {
int answer = 1;
int count = 1;
if(a == b || a == c || b == c) {
count++;
}
if(a == b && b == c) {
count++;
}
for(int i = 1; i <= count; i++) {
answer *= (pow(a,i)+pow(b,i)+pow(c,i));
}
return answer;
}
private int pow(int a, int b) {
if(b == 0) return 1;
return a * pow(a, b-1);
}
}
class Solution {
public int solution(int a, int d, boolean[] included) {
int answer = 0;
for(int i=0; i<included.length; i++){
if(included[i]){
answer += a+d*i;
}
}
return answer;
}
}
class Solution {
public String solution(String code) {
int mode=0;
String answer="";
for(int i=0; i<code.length(); i++){
if(mode==0) {
if(code.charAt(i)=='1' ){
mode=1;
} else {
if(i%2==0){
answer += code.charAt(i);
}
}
} else if(mode==1){
if(code.charAt(i)=='1' ){
mode=0;
} else {
if(i%2==1){
answer += code.charAt(i);
}
}
}
}
if(answer.equals("")){
answer = "EMPTY";
}
return answer;
}
}
class Solution {
public int solution(int[] num_list) {
int sum = 0;
int mul = 1;
for(int num : num_list){
sum += num;
mul *= num;
}
if(mul < sum*sum){
return 1;
} else {
return 0;
}
}
}
class Solution {
public int solution(int[] num_list) {
String odd="";
String even="";
for(int i=0; i<num_list.length; i++){
if(num_list[i]%2==0){
even += num_list[i];
} else {
odd += num_list[i];
}
}
return Integer.parseInt(odd) + Integer.parseInt(even);
}
}
class Solution {
public int solution(int[] num_list) {
int answer = 0;
int even = 0;
int odd = 0;
for(int num : num_list) {
if(num % 2 == 0) {
even *= 10;
even += num;
} else {
odd *= 10;
odd += num;
}
}
answer = even + odd;
return answer;
}
}
class Solution {
public int[] solution(int[] num_list) {
int length = num_list.length;
int[] result = new int[length+1];
for(int i=0; i<length;i++ ){
result[i]=num_list[i];
}
int last = num_list[length-1];
int prev = num_list[length-2];
if(prev >= last){
result[length] = 2* last;
} else {
result[length] = last-prev;
}
return result;
}
}
class Solution {
public int solution(int n, String control) {
char[] arr = control.toCharArray();
for(int i=0; i<control.length(); i++){
char a = arr[i];
if(a=='w'){
n+=1;
} else if(a=='s'){
n-=1;
} else if(a=='d'){
n+=10;
} else if(a=='a'){
n-=10;
}
}
return n;
}
}
class Solution {
public int solution(int n, String control) {
int answer = n;
for(char ch : control.toCharArray()) {
switch(ch) {
case 'w': answer += 1; break;
case 's': answer -= 1; break;
case 'd': answer += 10; break;
case 'a': answer -= 10; break;
default:break;
}
}
return answer;
}
}
class Solution {
public String solution(int[] numLog) {
String answer = "";
int len = numLog.length;
for(int i=1; i<len; i++){
int num=numLog[i]-numLog[i-1];
if (num == 1){
answer += "w";
} else if(num == -1){
answer += "s";
} else if(num == 10){
answer += "d";
} else if(num == -10){
answer += "a";
}
}
return answer;
}
}
class Solution {
public int[] solution(int[] arr, int[][] queries) {
for (int i = 0; i < queries.length; i++) {
int temp = arr[queries[i][0]];
arr[queries[i][0]] = arr[queries[i][1]];
arr[queries[i][1]] = temp;
}
return arr;
}
}
import java.util.Arrays;
class Solution {
public int[] solution(int[] arr, int[][] queries) {
int[] answer = new int[queries.length];
for (int i = 0; i < queries.length; i++) {
int s = queries[i][0];
int e = queries[i][1];
int k = queries[i][2];
int min = Integer.MAX_VALUE;
boolean exist = false;
for (int j = s; j <= e; j++) {
if (arr[j] > k && arr[j] < min) {
min = arr[j];
exist = true;
}
}
if (exist) {
answer[i] = min;
} else {
answer[i] = -1;
}
}
return answer;
}
}
import java.util.Arrays;
class Solution {
public int[] solution(int[] arr, int[][] queries) {
int[] answer = new int[queries.length];
Arrays.fill(answer, -1);//answer배열 -1로 초기화
for (int idx = 0; idx < queries.length; idx++) {
int[] query = queries[idx];
int s = query[0], e = query[1], k = query[2];
for (int i = s; i <= e; i++) {
if (k < arr[i]) {
answer[idx] = answer[idx] == -1 ? arr[i] : Math.min(answer[idx], arr[i]);
//Math.min(a,b) a와 b 중 더 작은 값을 반환
}
}
}
return answer;
}
}
import java.util.stream.IntStream;
class Solution {
public int[] solution(int l, int r) {
int[] answer = IntStream.rangeClosed(l, r).filter(i -> {
while (i > 0) {
if (i % 5 != 0) return false;
i /= 10;
}
return true;
}).toArray();
return answer.length == 0 ? new int[]{-1} : answer;
}
}
import java.util.ArrayList;
class Solution {
public int[] solution(int l, int r) {
ArrayList<Integer> list = new ArrayList<>();
for (int i = 1; i < 64; i++) {
int num = Integer.parseInt(Integer.toBinaryString(i)) * 5;
//Integer.toBinaryString : 10진수 <-> 2진수 변환
if (l <= num && num <= r)
list.add(num);
}
return list.isEmpty() ? new int[] { -1 } : list.stream().mapToInt(i -> i).toArray();
//리스트를 정수 배열로 변환
}
}
import java.util.ArrayList;
class Solution {
public int[] solution(int start, int end) {
int[] result = new int[end-start+1];
for(int i=start; i<=end; i++){
result[i-start]=i;
}
return result;
}
}
import java.util.stream.IntStream;
class Solution {
public int[] solution(int start, int end) {
return IntStream.rangeClosed(start, end).toArray();
}
}
import java.util.ArrayList;
import java.util.List;
class Solution {
public int[] solution(int n) {
List<Integer> list = new ArrayList<>();
list.add(n);
while(n!=1){
if(n%2==0){
n/=2;
} else {
n=3*n+1;
}
list.add(n);
}
int[] answer= new int[list.size()];//list를 int배열로 반환해야쥬
for(int i=0; i<list.size();i++){
answer[i]=list.get(i);
}
return answer;
}
}
class Solution {
public int[] solution(int n) {
return IntStream.concat(//두 instream 붙여
IntStream.iterate(n, i -> i > 1, i -> i % 2 == 0 ? i / 2 : i * 3 + 1),
//n부터 시작하여, i가 1보다 작아질때까지 실행
IntStream.of(1))//1을 추가하는 instream생성
.toArray();//int배열로반환
}
}
import java.util.*;
class Solution {
public int[] solution(int[] arr) {
int[] stk = new int[arr.length];
int i = 0;
int top = -1;
while (i < arr.length) {
if (top == -1 || stk[top] < arr[i]) {
stk[++top] = arr[i];
i++;
} else if (stk[top] >= arr[i]) {
top--;
}
}
return Arrays.copyOfRange(stk, 0, top + 1);
}
}
import java.util.*;
class Solution {
public Stack<Integer> solution(int[] arr) {
Stack<Integer> stack = new Stack<>();
int i = 0;
while (i < arr.length) {
if (stack.empty() || stack.peek() < arr[i]) {
stack.push(arr[i]);
i++;
} else if (stack.peek() >= arr[i]) {
stack.pop();
}
}
return stack;
}
}
class Solution {
public int solution(int a, int b, int c, int d) {
//모두 같을 때
if (a==b && b==c && c==d) {
return 1111 * a;
}
//세 주사위가 같을 때
else if (a==b && b==c) {
return (10 * a + d) * (10 * a + d);
}
else if (a==d && d==c) {
return (10 * a + b) * (10 * a + b);
}
else if (a==b && b==d) {
return (10 * a + c) * (10 * a + c);
}
else if (d==b && b==c) {
return (10 * d + a) * (10 * d + a);
}
//두 주사위가 모두 같을 때
else if ((a==b && c==d) || (a==c && b==d) || (a==d && b==c)) {
int p = Math.max(Math.max(a, b), Math.max(c, d));
int q = Math.min(Math.min(a, b), Math.min(c, d));
return (p + q) * Math.abs(p - q);
}
//두 주사위가 같고 나머지 주사위가 각각 다를 때
else if (a==b && c!=d) {
return c * d;
} else if (a==c && b!=d) {
return b * d;
} else if (a==d && b!=c) {
return b * c;
} else if (b==c && a!=d) {
return a * d;
} else if (b==d && a!=c) {
return a * c;
} else if (c==d && a!=b) {
return a * b;
}
//모두 다를 때
else {
return Math.min(Math.min(a, b), Math.min(c, d));
}
}
}
import java.util.Arrays;
class Solution {
public int solution(int a, int b, int c, int d) {
int[] dice = { a, b, c, d };
Arrays.sort(dice);
int ans = 0;
if (dice[0] == dice[3]) {
ans = 1111 * dice[3];
} else if (dice[0] == dice[2] || dice[1] == dice[3]) {
//math.pow(a,b) : a의 b제곱
ans = (int) Math.pow(dice[1] * 10 + (dice[0] + dice[3] - dice[1]), 2);
} else if (dice[0] == dice[1] && dice[2] == dice[3]) {
ans = (dice[0] + dice[3]) * (dice[3] - dice[0]);
} else if (dice[0] == dice[1]) {
ans = dice[2] * dice[3];
} else if (dice[1] == dice[2]) {
ans = dice[0] * dice[3];
} else if (dice[2] == dice[3]) {
ans = dice[0] * dice[1];
} else {
ans = dice[0];
}
return ans;
}
}
toArray
Stringbuilder : string과 문자열을 더할 때 새로운 객체를 생성하는 것이 아니라 기존의 데이터에 더하는 방식을 사용하여 속도가 빠르다.
StringBuilder sb = new StringBuilder();
sb.append("a");
sb.append("b");
System.out.print(sb.toString());
문자열 형변환 (객체를 String 문자열 참조 자료형으로 형 변환하는 역할)
import java.util.Arrays;
stream : 컬렉션 데이터를 선언형으로 쉽게 처리
List<Integer> redHeavyAppleUid = appleList.stream()
.filter(apple -> apple.getColor().equals("RED")) // 빨간색 사과 필터링
.sorted(Comparator.comparing(Apple::getWeight)) // 무게 순서대로 정렬
.map(Apple::getUidNum).collect(Collectors.toList()); // 사과 고유번호 출력