문제 URL : https://www.acmicpc.net/problem/10769
10769번: 행복한지 슬픈지
문제 승엽이는 자신의 감정을 표현하기 위해서 종종 문자 메시지에 이모티콘을 넣어 보내곤 한다. 승엽이가 보내는 이모티콘은 세 개의 문자가 붙어있는 구조로 이루어져 있으며, 행복한 얼굴��
www.acmicpc.net
문제접근법 : 문제가 너무 쉬우니 따로 설명안하겠습니다. c++ 코드와 파이썬 코드로 풀었습니다.
c++코드:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int happy=0,sad=0;
string s;
getline(cin,s);
for(int i=0;i<s.size()-2;i++)
{
if(s[i]==':'&&s[i+1]=='-')
{
if(s[i+2]==')')
happy++;
else if(s[i+2]=='(')
sad++;
}
}
if(happy==0&&sad==0)
cout<<"none"<<endl;
else if(happy>sad)
cout<<"happy"<<endl;
else if(happy<sad)
cout<<"sad"<<endl;
else
cout<<"unsure"<<endl;
}
|
cs |
파이썬코드 :
1
2
3
4
5
6
7
8
9
10
11
12
|
# -*- coding: euc-kr -*-
s= input()
cnt1=s.count(":-)")
cnt2=s.count(":-(")
if cnt1 ==0 and cnt2 == 0:
print("none")
elif cnt1>cnt2:
print("happy")
elif cnt1<cnt2:
print("sad")
else:
print("unsure")
|
cs |
파이썬이 제공해주는 함수만 제대로 알면 정말 쉽게 짤수 있으니 너무 편리하네요
'백준' 카테고리의 다른 글
백준 1927 놀라운 문자열 (0) | 2020.08.13 |
---|---|
백준 1411 비슷한 단어 (0) | 2020.08.10 |
백준 16943 숫자 재배치 (0) | 2020.08.07 |
백준 1956 운동 (0) | 2020.08.07 |
백준 11779 최소비용 구하기 2 (0) | 2020.08.07 |