#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
vector<int> solution(long long n) 
{
    
    vector<int> answer;
 
    // long long -> string
    string num = to_string(n);
 
    // reverse(num.begin(), num.end());
    for(int i = 0; i < num.size()/2; i++)
    {
        char temp = num[i];
        num[i] = num[num.size()-1-i];
        num[num.size()-1-i] = temp;
    }
    
    for(int i = 0; i < num.size(); i++)
    {
        answer.push_back(num[i]-'0');
    }
    
    return answer;
}
 
cs
#include <iostream>
#include <string>
using namespace std;
 
int solution(int n)
{
    int answer = 0;
    string num = to_string(n);
    
    for(int i = 0; i < num.size(); i++)
    {
        answer += num[i]-'0';
    }
 
    return answer;
}
cs
#include <string>
#include <vector>
#include <iostream>
using namespace std;
 
string solution(string s) 
{
    string answer = "";
   
    int wordCnt = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == ' ')
        {
            wordCnt = 0;
            answer += s[i];
            continue;
        }
        else
        {
            // 짝수 : 소문자->대문자, 대문자는 그대로
            if(wordCnt % 2 == 0)
            {
                // 대문자는 그대로
                if('A' <= s[i] && s[i] <= 'Z')
                {
                    answer += s[i];
                }
                else
                {
                    answer += s[i]-'a'+'A';
                }
            }
            // 홀수
            else
            {
                // 소문자는 그대로
                if('a' <= s[i] && s[i] <= 'z')
                {
                    answer += s[i];
                }
                else
                {
                    answer += s[i]-'A'+'a';
                }
            }
        }
        
        wordCnt++;
    }
    
    return answer;
}
cs
#include <string>
#include <vector>
using namespace std;
 
int find(int n)
{
    int answer = n;
    
    for(int i = 1; i <= n/2; i++)
    {
        if(n % i == 0)    
        {
            answer += i;
        }
    }
    
    return answer;
}
 
int solution(int n) 
{
    int answer = find(n);
    
    return answer;
}
cs
#include <string>
#include <vector>
using namespace std;
 
string solution(string s, int n)
{
    string answer = "";
    
    for(int i = 0; i < s.size(); i++)
    {
         if('A' <= s[i] && s[i] <= 'Z')
         {
             // 알파벳순서 A(0)~Z(25)
             int idx = s[i]-'A';
             int changeIdx = (idx+n) % 26;
             
             answer += 'A'+changeIdx;
         }
         else if('a' <= s[i] && s[i] <= 'z')
         {
             // 알파벳순서 a(0)~z(25)
             int idx = s[i]-'a';
             int changeIdx = (idx+n) % 26;
             
             answer += 'a'+changeIdx;
         }
        else if(s[i] == ' ')
        {
            answer += s[i];
        }
    }
    
    return answer;
}
cs
#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

+ Recent posts