문제
https://www.acmicpc.net/problem/10769
10769번: 행복한지 슬픈지
승엽이는 자신의 감정을 표현하기 위해서 종종 문자 메시지에 이모티콘을 넣어 보내곤 한다. 승엽이가 보내는 이모티콘은 세 개의 문자가 붙어있는 구조로 이루어져 있으며, 행복한 얼굴을 나
www.acmicpc.net
내가 작성한 코드
import java.io.*;
public class 백준10769 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
String input = br.readLine();
String happy = ":-)";
String sad = ":-(";
int h = 0;
int s = 0;
// happy 또는 sad가 있을 때
if(input.contains(happy) || input.contains(sad)){
for(int i = 0; i<input.length()-2; i++){
if(input.charAt(i)==':' && input.charAt(i+1)=='-' && input.charAt(i+2)==')'){
h++;
}
if(input.charAt(i)==':' && input.charAt(i+1)=='-' && input.charAt(i+2)=='('){
s++;
}
}
if(h==s){
bw.write("unsure");
}
else if(h>s){
bw.write("happy");
}
else{
bw.write("sad");
}
}
// happy 또는 sad가 없을 때
else{
bw.write("none");
}
bw.close();
}
}
'자바 > 백준' 카테고리의 다른 글
[백준 15740] A+B - 9 (0) | 2022.09.11 |
---|---|
[백준 11718] 그대로 출력하기 (0) | 2022.09.08 |
[백준 1158] 요세푸스 문제 (0) | 2022.09.07 |
[백준 6502] 동혁 피자 (0) | 2022.09.07 |
[백준 2440] 별 찍기 - 3 (0) | 2022.09.06 |