Created
July 8, 2020 19:39
-
-
Save anitainfo/18eba1eb59d10c8acb5e55f2ebcd26ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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