https://www.acmicpc.net/problem/10769
10769번: 행복한지 슬픈지
승엽이는 자신의 감정을 표현하기 위해서 종종 문자 메시지에 이모티콘을 넣어 보내곤 한다. 승엽이가 보내는 이모티콘은 세 개의 문자가 붙어있는 구조로 이루어져 있으며, 행복한 얼굴을 나
www.acmicpc.net
해석 및 팁
이문제는 이모티콘의 모양이 완전히 존재해야만 개수로 치기 때문에 입력받은 문자열 하나하나 나누어서 조건을 적용하여 계산하면 됩니다.
Java 코드
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int count_h = 0;
int count_s = 0;
String str= sc.nextLine();
String[] arr = str.split("");
for(int i = 0; i < arr.length-2; i++) {
if(arr[i].equals(":") && arr[i+1].equals("-") && arr[i+2].equals(")")) count_h++;
else if(arr[i].equals(":") && arr[i+1].equals("-") && arr[i+2].equals("(")) count_s++;
}
if(count_h == 0 && count_s == 0) System.out.println("none");
else if(count_h == count_s) System.out.println("unsure");
else if(count_h > count_s) System.out.println("happy");
else if(count_h < count_s) System.out.println("sad");
}
}
'백준' 카테고리의 다른 글
백준 1978 소수 찾기(Java) (0) | 2023.01.19 |
---|---|
백준 4673 셀프 넘버(Java) (0) | 2023.01.19 |
백준 3985 롤 케이크(Java) (0) | 2023.01.19 |
백준 9933 민균이의 비밀번호(Java) (0) | 2023.01.18 |
백준 14467 소가 길을 건너간 이유 1(Java) (0) | 2023.01.18 |