Submission #915798

#TimeUsernameProblemLanguageResultExecution timeMemory
915798andrei_iorgulescuTreasure (info1cup19_treasure)C++14
100 / 100
5 ms840 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin >> n >> k;
    stack<pair<char,int>>s;
    for (int i = 1; i <= n; i++)
    {
        char c;
        cin >> c;
        if (s.empty() == true or s.top().first != c)
            s.push({c,1});
        else
            s.top().second++;
        if (s.top().second == k)
            s.pop();
    }
    vector<char>v;
    while (!s.empty())
    {
        for (int i = 1; i <= s.top().second; i++)
            v.push_back(s.top().first);
        s.pop();
    }
    reverse(v.begin(),v.end());
    for (int i = 0; i < v.size(); i++)
        cout << v[i];
    return 0;
}

Compilation message (stderr)

treasure.cpp: In function 'int main()':
treasure.cpp:32:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i = 0; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...