#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
#include <string>
#include <vector>
using namespace std;
 
long long solution(int a, int b) 
{
    long long answer = 0;
    long long sum = 0;
    
    if(a > b)
    {
        int temp = a;
        a = b;
        b = temp;
    }
    
    for(int i = a; i <= b; i++)
    {
        sum += i;
    }
    answer = sum;
    
    return answer;
}
cs
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
vector<int> solution(vector<int> arr, int divisor) 
{
    vector<int> answer;
    
    int flag = 0;
    for(int i = 0; i < arr.size(); i++)
    {
        if(arr[i] % divisor == 0)
        {
            flag = 1;
            answer.push_back(arr[i]);
        }
    }
    
    sort(answer.begin(), answer.end());
    
    if(flag == 0)
    {
        answer.push_back(-1);
    }
    
    return answer;
}
cs
#include <vector>
using namespace std;
 
vector<int> solution(vector<int> arr) 
{
    vector<int> answer;
    
    int beforeNum = -1;
    for(int i = 0; i < arr.size(); i++)
    {
        if(arr[i] == beforeNum)
        {
            continue;
        }
        
        beforeNum = arr[i];
        answer.push_back(arr[i]);
    }
 
    return answer;
}
cs
#include <string>
#include <vector>
using namespace std;
 
string solution(string s) 
{
    string answer = "";
    
    if(s.size() % 2 == 0)
    {
        answer += s[s.size()/2-1];
        answer += s[s.size()/2];
    }
    else
    {
        answer += s[s.size()/2];
    }
        
    return answer;
}
cs
#include <string>
#include <vector>
using namespace std;
 
string solution(int a, int b) 
{
    string answer = "";
    string day[7= {"THU""FRI""SAT""SUN""MON""TUE""WED"};
    int month[12= {312931303130313130313031};
    
    int monthSum = 0;
    int daySum = 0;
    // 전달까지의 일 수 합산
    for(int i = 0; i < a-1; i++)
    {
        monthSum += month[i];
    }
    daySum = monthSum+b;
    
    int result = daySum % 7;
    
    answer += day[result];
    
    return answer;
}
cs

+ Recent posts