#include <string>
#include <vector>
using namespace std;
 
int solution(string s) 
{
    int answer = atoi(s.c_str());
    
    return answer;
}
cs
#include <string>
#include <vector>
using namespace std;
 
string solution(int n) 
{
    string answer = "";
    string plus = "수박";
    
    if(n == 1)
    {
        return "수";
    }
    else if(n == 2)
    {
        return "수박";
    }
    else
    {
        // 홀수
        if(n % 2 == 1)
        {
            for(int i = 1; i <= n/2; i++)
            {
                answer += plus;
            }
            answer += "수";
        }
        // 짝수
        else if(n % 2 == 0)
        {
            for(int i = 1; i <= n/2; i++)
            {
                answer += plus;
            }
        }
    }
 
    return answer;
}
cs
#include <string>
#include <vector>
using namespace std;
 
int find_decimal(int n)
{
    int cnt = 0;
    int a[1000000= {0};
    
    // 에라토스테네스의 체
    for(int i = 2; i <= n; i++)
    {
        if(a[i] == 1)
        {
            continue;
        }
        
        for(int j = i+i; j <= n; j+=i)
        {
            a[j] = 1;
        }
    }
    
    for(int i = 2; i <= n; i++)
    {
        if(a[i] == 0)
        {
            cnt++;
        }
    }
    
    return cnt;
}
 
int solution(int n) 
{
    int answer = find_decimal(n);
    
    return answer;
}
cs
#include <string>
#include <vector>
using namespace std;
 
string solution(vector<string> seoul) 
{
    string answer;
    
    int kimIdx = 0;
    for(int i = 0; i < seoul.size(); i++)
    {
        if(seoul[i] == "Kim")
        {
            kimIdx = i;
            break;
        }
    }
    
    answer = "김서방은 " + to_string(kimIdx) + "에 있다";
    return answer;
}
cs
#include <string>
#include <vector>
using namespace std;
 
bool solution(string s) 
{
    int flag = 0;
    
    if(s.size() == 4 || s.size() == 6)
    {
        for(int i = 0; i < s.size(); i++)
        {
            if('0' <= s[i] && s[i] <= '9')
            {
                continue;
            }
            else
            {
                flag = 1;
                break;
            }
        }
 
        if(flag == 1)
        {
            return false;
        }
        else
        {
            return true;
        }   
    }
    else
    {
        return false;
    }
}
cs
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
bool cmp(char a, char b)
{
    if(a <= b)
    {
        return false;
    }
    else
    {
        return true;   
    }
}
 
string solution(string s) 
{
    // sort(s.begin(), s.end(), greater<char>());
    sort(s.begin(), s.end(), cmp);
    
    return s;
}
cs
#include <string>
#include <iostream>
using namespace std;
 
bool solution(string s)
{
    int pCnt = 0;
    int yCnt = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'P' || s[i] == 'p')
        {
            pCnt++;
        }
        else if(s[i] == 'Y' || s[i] == 'y')
        {
            yCnt++;
        }
    }
    
    if(pCnt == yCnt)
    {
        return true;
    }
    else
    {
        return false;
    }
}
cs
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
int chk;
 
bool cmp(string a, string b)
{
    if(a[chk] <= b[chk])
    {
        if(a[chk] == b[chk])
        {
            if(a < b)
            {
                return true;
            }
            else
            {
                return false;
            }
        }   
        
        return true;
    }
    else
    {
        return false;
    }
}
 
vector<string> solution(vector<string> strings, int n) 
{
    vector<string> answer;
    chk = n;
    
    sort(strings.begin(), strings.end(), cmp);
 
    answer = strings;
    
    return answer;
}
cs

+ Recent posts