Skip to content

Instantly share code, notes, and snippets.

@anitainfo
Created July 8, 2020 19:39
Show Gist options
  • Save anitainfo/18eba1eb59d10c8acb5e55f2ebcd26ff to your computer and use it in GitHub Desktop.
Save anitainfo/18eba1eb59d10c8acb5e55f2ebcd26ff to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
int cont[27];
int main()
{
int k,res=0;
char palavra[1010];
scanf("%d", &k);
scanf("%s[^\n]", palavra);
int tamanho = strlen(palavra);
for(int i=0; i<tamanho; i++)
{
int letra=palavra[i]-96;
cont[letra]++;
}
for(int i=1; i<=26; i++)
if(cont[i]%k==0)res+=cont[i];
if(res==tamanho)
{
if(k!=1)
{
while(k>0)
{
for(int i=1; i<=26; i++)
{
if(cont[i]>0)
{
int vezes=cont[i]/k;
while(vezes>0)
{
printf("%c",i+96);
cont[i]--;
vezes--;
}
}
}
k--;
}
}
else printf("%s",palavra);
}
else printf("-1");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment