내일배움캠프 34일차 TIL _ 7주 5일차
2024. 5. 31. 21:47ㆍTIL Java
- 오늘 있었던 일
- 개인과제
- 알고리즘
SPRIONG
- 스프링 정리
더보기
API 및 ERD
- API
- 유저 api
- 일정 api
-
- 댓글 api
- ERD
- UCD
알고리즘 문제 풀기
● 성격 유형 검사하기
더보기
● 성격 유형 검사하기 //링크
class Solution {
public String solution(String[] survey, int[] choices) {
String[] fus = {"R","C","J","A"};
String[] bak = {"T","F","M","N"};
int[] good = new int[4];
for (int i = 0; i < survey.length; i++) {
String test= survey[i];
for (int j = 0; j < 4; j++) {
if (test.contains( fus[j] )) {
if(choices[i] == 4){
break;
}
int v = 4 - choices[i];
if(test.indexOf(fus[j]) == 0){
good[j] += v * -1;
break;
}else {
good[j] += v;
break;
}
}
}
}
String answer = "";
for (int i = 0; i < 4; i++) {
if( good[i] > 0){
answer += bak[i];
}else if (good[i] == 0) {
int b = ( bak[i] ).charAt( 0 );
int f = ( fus[i] ).charAt( 0 );
if( b > f){
answer += fus[i];
}else {
answer += bak[i];
}
}else{
answer += fus[i];
}
}
return answer;
}
}
- 한번에 통과함.
- 저번에 배운대로 배열 여러 가지를 써서 만들었다 = 통과
- 밑은 다른 사람의 풀이
-
import java.util.HashMap; class Solution { public String solution(String[] survey, int[] choices) { String answer = ""; char [][] type = {{'R', 'T'}, {'C', 'F'}, {'J', 'M'}, {'A', 'N'}}; int [] score = {0, 3, 2, 1, 0, 1, 2, 3}; HashMap<Character, Integer> point = new HashMap<Character, Integer>(); // 점수 기록할 배열 초기화 for (char[] t : type) { point.put(t[0], 0); point.put(t[1], 0); } // 점수 기록 for (int idx = 0; idx < choices.length; idx++){ if(choices[idx] > 4){ point.put(survey[idx].charAt(1), point.get(survey[idx].charAt(1)) + score[choices[idx]]); } else { point.put(survey[idx].charAt(0), point.get(survey[idx].charAt(0)) + score[choices[idx]]); } } // 지표 별 점수 비교 후 유형 기입 for (char[] t : type) { answer += (point.get(t[1]) <= point.get(t[0])) ? t[0] : t[1]; } return answer; } }
- 나와 다르게 처음 부터 char 값으로 만들고 마지막에 삼향 연산자를 이용해 나보다 효율적으로했다... 이렇게 할껄
당일 회고
- 스프링 AOP는 또 뭐야아아아ㅏ악
'TIL Java' 카테고리의 다른 글
내일배움캠프 36일차 TIL _ 8주 2일차 (1) | 2024.06.04 |
---|---|
내일배움캠프 35일차 TIL _ 8주 1일차 (0) | 2024.06.03 |
내일배움캠프 33일차 TIL _ 7주 4일차 (0) | 2024.05.30 |
내일배움캠프 31일차 TIL _ 7주 2일차 (0) | 2024.05.28 |
내일배움캠프 30일차 TIL _ 7주 1일차 (0) | 2024.05.27 |