Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- ㅣ풀이
- 백준 17471
- 구현
- 백준 17779
- 버킷 정렬
- Stack 이란
- 자료구조
- 해시구현
- 스택의 특징
- c#
- 시간 복잡도
- 백준 5397
- 백준 17822
- dfs
- 백준 1406
- AVL 시간 복잡도
- 백준 1158
- 원판 돌리기
- 해시 구현
- qorwns
- 별 찍기 10
- C/C++ 구현
- 조세퍼스 순열
- 백준
- heap
- 1764
- 게리멘더링2
- 풀이
- 5397
- 백준 2447
Archives
- Today
- Total
홍시홍의 프로그래밍
[2017 카카오 코딩테스트] 다트 게임 본문
분류
시뮬레이션
요구사항
다트 던진 경기 결과 값 구하기
풀이
다트를 3번 던지고
S, D, T와 *, #만 주어진 대로 처리하면 된다
*을 처리하기 위해서 flag배열을 사용하여 1->3의 순서로 *이 주어졌다면 이전 index에 *을 추가하였다
나머지는 문제에서 주어진 대로 하드코딩하였다
#include <string>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <algorithm>
#include <deque>
#include <map>
using namespace std;
struct go{
int x;
int y;
int z;
};
vector<string> v1;
int main(){
//1S2D*3T
//0 48 9 57
string str= "1T2D3D#";
int cnt=0;
vector<string> v[5];
vector<int> answer;
int flag[5]={0,}; //*2 +1
string temp;
for(auto i : str){
char ch=i;
if(i>=48 && i<=57){
v[cnt].push_back(temp);
temp.clear();
cnt++;
}
temp+=i;
if(i=='*'){
flag[cnt]++;
}
}
if(flag[2]==1){
flag[1]++;
}
if(flag[3]==1){
flag[2]++;
}
v[cnt].push_back(temp);
for(int i=1; i <=3 ; i++){
int tempnum=0;
int mulnum=0;
string nowstr=v[i].front();
tempnum=stoi(v[i].front());
mulnum=tempnum;
if(nowstr[0]==49 && nowstr[1]==0){
tempnum=10;
mulnum=tempnum;
}
if(tempnum==10){
for(int j=2 ; j<nowstr.size() ; j++){
if(j==0){
tempnum=nowstr[j]-48;
mulnum=tempnum;
}
if(nowstr[j]=='S'){
continue;
}
else if(nowstr[j]=='D'){
for(int k=0 ; k<1 ; k++)
tempnum*=mulnum;
}
else if(nowstr[j]=='T'){
for(int k=0 ; k<2 ; k++)
tempnum*=mulnum;
}
if(nowstr[j]=='#'){
tempnum*=-1;
}
}
}
else{
for(int j=1 ; j<nowstr.size() ; j++){
if(j==0){
tempnum=nowstr[j]-48;
mulnum=tempnum;
}
if(nowstr[j]=='S'){
continue;
}
else if(nowstr[j]=='D'){
for(int k=0 ; k<1 ; k++)
tempnum*=mulnum;
}
else if(nowstr[j]=='T'){
for(int k=0 ; k<2 ; k++)
tempnum*=mulnum;
}
if(nowstr[j]=='#'){
tempnum*=-1;
}
}
}
for(int j=0; j< flag[i]; j++){
tempnum*=2;
}
answer.push_back(tempnum);
}
int ans=0;
for(auto i : answer){
ans+=i;
}
cout<<ans<<endl;
}
'알고리즘 문제풀이 > 카카오' 카테고리의 다른 글
[2017 카카오 코딩테스트] 뉴스 클러스터링 (0) | 2020.08.04 |
---|---|
[2017 카카오 코딩테스트] 비밀 지도 (0) | 2020.07.24 |
[2017 카카오 코딩테스트] 캐시 (0) | 2020.07.24 |
[2020 카카오 인턴십 코딩테스트] 경주로 건설 (0) | 2020.07.23 |
[2020 카카오 인턴십 코딩테스트] 수식 최대화 (0) | 2020.07.23 |
Comments