#include <string>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
 
vector<int> solution(int n, vector<string> words) 
{
    vector<int> answer;
    map<stringint> visited;
    int people = 0;
    int peopleTurn = 0;
    bool flag = false;
    
    for(int i = 0; i < words.size(); i++)
    {
        if(visited[words[i]] == 0)
        {   
            if(i == 0)
            {
                visited[words[i]] = 1;
                continue;
            }
            else
            {
                char last = words[i-1][words[i-1].size()-1];
                
                // 단어를 잘못 말한 경우
                if(last != words[i][0])
                {
                    if((i+1) % n == 0)
                    {
                        people = n;
                        peopleTurn = (i+1/ n;
                    }
                    else
                    {
                        people = (i+1) % n;
                        peopleTurn = (i+1/ n + 1;
                    }
                    
                    flag = true;
                    break;
                }
                else
                {
                    visited[words[i]] = 1;
                }
            }
        }
        // 나온 단어를 다시 말한 경우
        else
        {
            if((i+1) % n == 0)
            {
                people = n;
                peopleTurn = (i+1/ n;
            }
            else
            {
                people = (i+1) % n;
                peopleTurn = (i+1/ n + 1;
            }
            
            flag = true;
            break;
        }
    }
    
    if(flag)
    {
        answer.push_back(people);
        answer.push_back(peopleTurn);   
    }
    else
    {
        answer.push_back(0);
        answer.push_back(0);   
    }
 
    return answer;
}
cs

1.

#include <string>
#include <vector>
#include <iostream>
using namespace std;
 
string solution(string s) 
{
    string answer = "";
 
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == ' ')
        {
            answer += s[i];
            continue;
        }
        else
        {
            // 공백 이후 첫문자 or 맨 첫문자
            if(s[i-1== ' ' || i == 0)
            {
                // 첫문자가 소문자인 경우 -> 대문자
                if('a' <= s[i] && s[i] <= 'z')
                {
                    s[i] = s[i]-'a'+'A';
                }
            }
            // 이어지는 문자가 대문자인 경우 -> 소문자
            else
            {
                if('A' <= s[i] && s[i] <= 'Z')
                {
                    s[i] = s[i]-'A'+'a';
                }
            }
        }
        
        answer += s[i];
    }
    
    return s;
}
cs

 

 

2.

#include <string>
#include <vector>
#include <iostream>
using namespace std;
 
string solution(string s) 
{
    bool flag = true;
 
    for(int i = 0; i < s.size(); i++)
    {
        if(flag)
        {
            // 공백 이후 첫문자가 소문자인 경우 -> 대문자로 변경
            if('a' <= s[i] && s[i] <= 'z')
            {
                s[i] = s[i]-'a'+'A';
            }
            
            flag = false;
        }
        else
        {
            // 이어지는 문자가 대문자인 경우 -> 소문자로 변경
            if('A' <= s[i] && s[i] <= 'Z')
            {
                s[i] = s[i]-'A'+'a';
            }
        }
        
        if(s[i] == ' ')
        {
            flag = true;
        }
    }
    
    return s;
}
cs
#include <string>
#include <vector>
#include <iostream>
using namespace std;
 
vector<vector<int>> solution(vector<vector<int>> arr1, vector<vector<int>> arr2) 
{
    vector<vector<int>> answer;
    
    for(int i = 0; i < arr1.size(); i++)
    {
        vector<int> temp; 
        
        for(int k = 0; k < arr2[0].size(); k++)
        {
            int sum = 0;   
            
            for(int j = 0; j < arr1[i].size(); j++)
            {     
                sum += arr1[i][j] * arr2[j][k];
            }   
            
            temp.push_back(sum);
        }
        
        answer.push_back(temp);
    }
    
    return answer;
}
cs
#include <string>
#include <vector>
using namespace std;
 
int fibo[1000000];
 
int find_fibo(int n)
{
    if(n == 0)
    {
        return 0;
    }
    else if(n == 1)
    {
        return 1;
    }
    else if(fibo[n] != 0)
    {
        return fibo[n];
    }
    else
    {
        return fibo[n] = (find_fibo(n-1+ find_fibo(n-2)) % 1234567;
    }
}
 
int solution(int n) 
{
    int answer = find_fibo(n);
    
    return answer;
}
cs
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int solution(vector<int> A, vector<int> B)
{
    int visitedA[1000= {0};
    int visitedB[1000= {0};
    
    // 오름차순 정렬
    sort(A.begin(), A.end());
    // 내림차순 정렬
    sort(B.begin(), B.end(), greater<int>());
    
    int sum = 0;
    for(int i = 0; i < A.size(); i++)
    {
        for(int j = i; j < B.size(); j++)
        {
            if(visitedA[i] == 0 && visitedB[j] == 0)
            {
                visitedA[i] = 1;
                visitedB[j] = 1;
                sum += A[i] * B[j];
                break;
            }
        }
    }
 
    return sum;
}
cs
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
 
bool cmp(string a, string b)
{
    int numA = stoi(a);
    int numB = stoi(b);
    
    if(numA <= numB)
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
string solution(string s) 
{
    vector<string> v;
    string temp = "";
    string answer = "";
    
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == ' ')
        {
            v.push_back(temp);
            temp = "";
            continue;
        }
        else
        {
            temp += s[i];        
        }
    }
    v.push_back(temp);
    
    sort(v.begin(), v.end(), cmp);
 
    answer += v[0];
    answer += " ";
    answer += v[v.size()-1];
    
    return answer;
}
cs
#include <vector>
#include <queue>
#include <algorithm>
#include <string.h>
using namespace std;
 
int visited[100][100];
int row, col;
 
int dx[4= {-1100}; // 상하좌우
int dy[4= {00-11}; // 상하좌우
 
int safe(int x, int y)
{
    if(x >= 0 && y >= 0 && x < row && y < col)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
 
int BFS(int x, int y, int color, vector<vector<int>> picture)
{
    queue<pair<intint>> q;
    q.push({x, y});
    visited[x][y] = 1;
    int cnt = 1;
    
    while(!q.empty())
    {
        x = q.front().first;
        y = q.front().second;
        q.pop();
        
        for(int i = 0; i < 4; i++)
        {
            int xpos = x+dx[i];
            int ypos = y+dy[i];
            
            if(safe(xpos, ypos) == 1 && picture[xpos][ypos] == color && visited[xpos][ypos] == 0)
            {
                q.push({xpos, ypos});
                visited[xpos][ypos] = 1;
                cnt++;
            }
        }    
    }
    
    return cnt;
}
 
// 전역 변수를 정의할 경우 함수 내에 초기화 코드를 꼭 작성해주세요. 
vector<int> solution(int m, int n, vector<vector<int>> picture) 
{
    int number_of_area = 0;
    int max_size_of_one_area = 0;
    
    memset(visited, 0sizeof(visited));
    row = m;
    col = n;
    
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j < col; j++)
        {
            if(picture[i][j] != 0 && visited[i][j] == 0)
            {
                int temp = BFS(i, j, picture[i][j], picture);
                max_size_of_one_area = max(temp, max_size_of_one_area);
                number_of_area++;
            }
        }
    }
    
    vector<int> answer;
    answer.push_back(number_of_area);
    answer.push_back(max_size_of_one_area);
    
    return answer;
}
cs
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int solution(vector<vector<int>> land)
{
    int sum[100000][4= {land[0][0], land[0][1], land[0][2], land[0][3]};
    
    for(int i = 1; i < land.size(); i++)
    {
        sum[i][0= max({sum[i-1][1]+land[i][0], sum[i-1][2]+land[i][0], sum[i-1][3]+land[i][0]});
        sum[i][1= max({sum[i-1][0]+land[i][1], sum[i-1][2]+land[i][1], sum[i-1][3]+land[i][1]});
        sum[i][2= max({sum[i-1][0]+land[i][2], sum[i-1][1]+land[i][2], sum[i-1][3]+land[i][2]});
        sum[i][3= max({sum[i-1][0]+land[i][3], sum[i-1][1]+land[i][3], sum[i-1][2]+land[i][3]});
    }
    
    int Max = max({sum[land.size()-1][0], sum[land.size()-1][1], sum[land.size()-1][2], sum[land.size()-1][3]});
    
    return Max;
}
cs

+ Recent posts