본문 바로가기
Code/baekjoon [ 단계별 ]

백준 단계별 <문자열2 >

by jaeaemin 2022. 2. 28.

 

 

2908 자바

상수

 

 

 

 

import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Q2908 {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);

        StringTokenizer st = new StringTokenizer(sc.nextLine(), " ");
        String tmp1 = st.nextToken();
        String tmp2 = st.nextToken();
        String win = "0";


        for (int i = 2; i >= 0; i--) {
            char c1 = tmp1.charAt(i);
            char c2 = tmp2.charAt(i);

            if (win == "0") {
                if (c1 == c2) {
                    System.out.print(c1);
                    continue;
                } else {
                    if (c1 > c2) win = tmp1;
                    else win = tmp2;
                    System.out.print(win.charAt(i));
                }
            }
            else {
                System.out.print(win.charAt(i));
            }
        }
    }
}

 

 

 

 

 

5622 자바

다이얼 

 

 

package StringEX;

import java.util.Scanner;

public class Q5622 {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String call = sc.nextLine();
        int ans = 0;

        for(int i=0; i<call.length(); i++){
            char c = call.charAt(i);

            switch(c) {
                case 'A': case 'B': case 'C' :
                    ans+=2;
                    break;
                case 'D': case 'E': case 'F' :
                    ans+=3;
                    break;
                case 'G': case 'H': case 'I' :
                    ans+=4;
                    break;
                case 'J': case 'K': case 'L' :
                    ans+=5;
                    break;
                case 'M': case 'N' : case'O':
                    ans+=6;
                    break;
                case 'P': case 'Q': case'R': case'S':
                    ans+=7;
                    break;
                case 'T': case 'U': case 'V':
                    ans+=8;
                    break;
                case 'W': case 'X': case 'Y': case 'Z':
                    ans+=9;
                    break;
            }
            ans++;
        }
        System.out.println(ans);
    }
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Q1316 자바

그룹단어 체크 

 

package StringEX;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Q1316 {
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int wordCnt = Integer.parseInt(br.readLine());

        int ans = 0;

        for(int i=0; i<wordCnt; i++){
            String checkWord = br.readLine();
            boolean isGroupWord = true;
            boolean[] checkBox = new boolean[26];
            int previous = checkWord.charAt(0);

            for(int j=0; j<checkWord.length(); j++){
                int present = checkWord.charAt(j) % 26;
                if(checkBox[present]== false){
                    checkBox[present] = true;
                    previous = present;
                }
                else{
                    if(previous == present) continue;
                    else{
                        isGroupWord = false;
                        break;
                    }
                }
            }
            if(isGroupWord == true) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}

 

 

 

 

반응형

'Code > baekjoon [ 단계별 ]' 카테고리의 다른 글

백준 단계별 <문자열>  (0) 2022.02.25
백준 단계별  (0) 2022.02.21
백준 단계별 문제 <함수>  (0) 2022.02.20
백준 단계별 문제 <배열>  (0) 2022.02.19
백준 단계별 문제 <1차원 배열>  (0) 2022.02.16