#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <queue>
using namespace std;
 
int N, K;
queue<int> q;
 
int main(void)
{
//    freopen("B1158_input.txt", "r", stdin);
    
    cin >> N >> K;
    
    for(int i = 1; i <= N; i++)
    {
        q.push(i);
    }
    
    cout << "<";
    while(!q.empty())
    {
        if(q.size() == 1)
        {
            cout << q.front() << ">";
            q.pop();
            
            break;
        }
        
        int cnt = 1;
        
        while(cnt != K)
        {
            int temp = q.front();
            q.pop();
            q.push(temp);
            
            cnt++;    
        }
        
        if(cnt == K)
        {
            cout << q.front() << ", ";
            q.pop();
        }
    }
    
    return 0;
}
cs

1.

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <list>
using namespace std;
 
string s;
int commandNum;
list<char> l;
 
int main(void)
{
//    freopen("B1406_input.txt", "r", stdin);
 
    cin >> s >> commandNum;
    
    for(int i = 0; i < s.size(); i++)
    {
        l.push_back(s[i]);
    }
    
    // 커서 생성 
    auto cur = l.end();
    
    for(int i = 1; i <= commandNum; i++)
    {
        char command;
        cin >> command;
        
        if(command == 'P')
        {
            char data;
            cin >> data;
            
            l.insert(cur, data);
        }
        else if(command == 'L')
        {
            if(cur != l.begin())
            {
                cur--;    
            }
        }
        else if(command == 'D')
        {
            if(cur != l.end())
            {
                cur++;
            }
        }
        else if(command == 'B')
        {
            if(cur != l.begin())
            {
                cur--;
                cur = l.erase(cur);
            }
        }
    }
    
    for(auto i = l.begin(); i != l.end(); i++)
    {
        cout << *i;
    }
    
    return 0;
}
cs

 

2.

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <stdlib.h>
using namespace std;
 
typedef struct node
{
    struct node *prev;
    struct node *next;
    char data;
}node;
 
node *head = NULL;
node *cur = NULL;
 
string s;
int commandNum;
 
void insert(char data)
{
    node *newNode = (node*)malloc(sizeof(node)*1);
    newNode->data = data;
    newNode->prev = NULL;
    newNode->next = NULL;
    
    if(head->next == NULL)
    {
        head->next = newNode;
        newNode->prev = head;
        
        cur = newNode;
    }
    else if(cur->next == NULL)
    {
        newNode->prev = cur;
        cur->next = newNode;
 
        cur = newNode;
    }
    // 중간에 삽입할 경우 
    else if(cur->next != NULL)
    {
        newNode->next = cur->next;
        cur->next->prev = newNode;
        
        cur->next = newNode;
        newNode->prev = cur;
        
        cur = newNode;
    }
}
 
void left()
{
    if(cur->prev != NULL)
    {
        cur = cur->prev;
    }
}
 
void right()
{
    if(cur->next != NULL)
    {
        cur = cur->next;
    }
}
 
void del()
{
    if(cur != head)
    {
        cur->prev->next = cur->next;
        
        // 중간에 삭제하는 경우 
        if(cur->next != NULL)
        {
            cur->next->prev = cur->prev;
        }
        else
        {
            cur->next = NULL;
        }
        
        cur = cur->prev;
    }
}
 
int main(void)
{
//    freopen("B1406_input.txt", "r", stdin);
    
    head = (node*)malloc(sizeof(node)*1);
    head->next = NULL;
    head->prev = NULL;
    
    cin >> s >> commandNum;
    
    for(int i = 0; i < s.size(); i++)
    {
        insert(s[i]);
    }
    
    for(int i = 1; i <= commandNum; i++)
    {
        char command;
        cin >> command;
        
        if(command == 'P')
        {
            char data;
            cin >> data;
            
            insert(data);
        }
        else if(command == 'L')
        {
            left();    
        }
        else if(command == 'D')
        {
            right();
        }
        else if(command == 'B')
        {
            del();
        }
    }
    
    cur = head->next;
    while(cur != NULL)
    {
        cout << cur->data;
        
        cur = cur->next;
    }
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
using namespace std;
 
int N;
int Max;
long long MaxNum;
map<long longint> counting;
vector<long long> reserve;
 
int main(void)
{
//    freopen("B11652_input.txt", "r", stdin);
    
    cin >> N;
    
    for(int i = 1; i <= N; i++)
    {
        long long temp;
        cin >> temp;
        
        if(counting[temp] == 0)
        {
            reserve.push_back(temp);
            counting[temp] = 1;
        }
        else
        {
            counting[temp]++;
        }
    }
    
    sort(reserve.begin(), reserve.end());
        
    for(int i = 0; i < reserve.size(); i++)
    {
        if(counting[reserve[i]] > Max)
        {
            Max = counting[reserve[i]];
            MaxNum = reserve[i];
        }
    }
    
    cout << MaxNum;
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
 
int N;
pair<intint> dot[100010];
 
bool cmp(pair<intint> a, pair<intint> b)
{
    if(a.first < b.first)
    {
        return true;
    }
    else if(a.first == b.first)
    {
        if(a.second < b.second)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
 
int main(void)
{
//    freopen("B11650_input.txt", "r", stdin);
    
    scanf("%d"&N);
    
    for(int i = 0; i < N; i++)
    {
        scanf("%d %d"&dot[i].first, &dot[i].second);
    }
 
    sort(dot, dot+N, cmp);
    
    for(int i = 0; i < N; i++)
    {
        printf("%d %d\n", dot[i].first, dot[i].second);
    }
    
    return 0;
}
cs
#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
 
int N;
pair<intint> dot[100010];
 
bool cmp(pair<intint> a, pair<intint> b)
{
    if(a.second < b.second)
    {
        return true;
    }
    else if(a.second == b.second)
    {
        if(a.first < b.first)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}
 
int main(void)
{
//    freopen("B11651_input.txt", "r", stdin);
    
    scanf("%d"&N);
    
    for(int i = 0; i < N; i++)
    {
        scanf("%d %d"&dot[i].first, &dot[i].second);
    }
 
    sort(dot, dot+N, cmp);
    
    for(int i = 0; i < N; i++)
    {
        printf("%d %d\n", dot[i].first, dot[i].second);
    }
    
    return 0;
}
cs
#include <iostream>
#include <algorithm>
using namespace std;
 
int N;
long long card[1010];
long long dp[1010];
 
long long solve(int cnt)
{
    if(dp[cnt] != 0)
    {
        return dp[cnt];
    }
 
    for(int i = 1; i <= N; i++)
    {
        if(cnt+<= N)
        {
            dp[cnt] = max(dp[cnt], solve(cnt+i) + card[i]);    
        }
    }
    
    return dp[cnt];
}
 
int main(void)
{
//    freopen("B11052_input.txt", "r", stdin);
    
    cin >> N;
    
    for(int i = 1; i <= N; i++)
    {
        cin >> card[i];
    }
    
    cout << solve(0);
    
    return 0;
}
cs
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;
 
#define MOD 1000000
 
string N;
long long dp[5010];
 
long long solve(int idx)
{
    if(idx >= N.size())
    {
        return 0;
    }
    else if(idx == N.size()-1)
    {
        return 1;
    }
    
    if(dp[idx] != 0)
    {
        return dp[idx];
    }
    
    if('1' <= N[idx+1])
    {
        dp[idx] = solve(idx+1) % MOD;    
    }
    
    if((N[idx+1== '1'|| (N[idx+1== '2' && N[idx+2<= '6'))
    {
        dp[idx] = (dp[idx] + solve(idx+2)) % MOD;    
    }
    
    return dp[idx];
}
 
int main(void)
{
//    freopen("B2011_input.txt", "r", stdin);
    
    cin >> N; 
    
    N = "0" + N;
    
    cout << solve(0);
    
    return 0;
}
cs
#include <iostream>
#include <algorithm>
using namespace std;
 
int N;
long long dp[110];
 
long long solve(int num)
{
    if(1 <= num && num <= 3)
    {
        return 1;
    }
    else if(4 <= num && num <= 5)
    {
        return 2;
    }
    
    if(dp[num] != 0)
    {
        return dp[num];
    }
    
    dp[num] = solve(num-1+ solve(num-5);
    
    return dp[num];
}
 
int main(void)
{
//    freopen("B9461_input.txt", "r", stdin);
    
    cin >> N;
    
    for(int i = 1; i <= N; i++)
    {
        int temp;
        cin >> temp;
        
        cout << solve(temp) << endl;    
    }
    
    return 0;
}
cs

+ Recent posts