IT's 우

[java]프로그래머스 - 성격 유형 검사하기, String에 char 추가하기 String+=char 본문

알고리즘/프로그래머스

[java]프로그래머스 - 성격 유형 검사하기, String에 char 추가하기 String+=char

디우 2022. 10. 3. 18:15
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/118666

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

String에 char 추가하기

 String answer = "";
 char plus='A';
 //+로 추가하기
 answer= answer + plus;

 


 

코드
-> 그냥 노가다로 풀었는데 점수는 70점... 왜일깡? 
class Solution {
    static int R,T,C,F,J,M,A,N;
    public String solution(String[] survey, int[] choices) {
        R=0;
        T=0;
        C=0;
        F=0;
        J=0;
        M=0;A=0;N=0;
        for(int i=0;i<survey.length;i++){
            char []now=survey[i].toCharArray();
            int choice=choices[i];
            if(choice==1){
                cho(now[0],3);
            }else if(choice==2){
                cho(now[0],2);
            }else if(choice==3){
                cho(now[0],1);
            }else if(choice==5){
                cho(now[1],1);
            }else if(choice==6){
                cho(now[1],2);
            }else if(choice==7){
                cho(now[1],3);
            }
        }
        String answer = "";
        if(R>=T){
            answer+='R';
        }else answer+='T';
        
        if(C>=F){
            answer+='C';
        }else answer+='F';
        
        if(J>=M){
            answer+='J';
        }else answer+='M';
        
        if(A>=N){
            answer+='A';
        }else answer+='N';
        
        return answer;
    }
    
    static void cho(char c, int score){
        if(c=='R') {R++;}
        else if(c=='T') {T+=score;}
        else if(c=='F') {F+=score;}
        else if(c=='C') {C+=score;}
        else if(c=='M') {M+=score;}
        else if(c=='J') {J+=score;}
        else if(c=='A') {A+=score;}
        else if(c=='N') {N+=score;}
    }
}
728x90
반응형