Skip to content

Instantly share code, notes, and snippets.

@murilomaeda
Created August 15, 2023 21:22
Show Gist options
  • Save murilomaeda/b232bcb579ae0f0aed257a4b915fde37 to your computer and use it in GitHub Desktop.
Save murilomaeda/b232bcb579ae0f0aed257a4b915fde37 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n; cin >> n;
string s; cin >> s;
//vamos considerar que já estamos incluindo o primeiro caractere
int k = 1;
for(int i = 1; i < s.length(); i++)
{
if(s[i] == s[i-1]) k++;
if(s[i] != s[i-1])
{
cout << k << " " << s[i-1] << " ";
k = 1;
}
}
cout << k << " " << s[s.length() - 1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment