1. 程式人生 > >【Henu ACM Round#24 A】k-String

【Henu ACM Round#24 A】k-String

push -s stdin spa 字母 open DC color 直接

【鏈接】 我是鏈接,點我呀:)
【題意】


在這裏輸入題意

【題解】


如果是一個k-string的話。
考慮最後的串假設形式為sss..ss(k個s)
則s中出現的字母,整個串中最後出現的次數肯定為k的倍數。

如果某個字母出現的次數不為k的倍數。
那麽直接輸出-1
否則。
我們把每個字母出現的次數/k分到每個部分就好。

【代碼】

#include <bits/stdc++.h>
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define all(x) x.begin(),x.end() #define pb push_back #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 using namespace std; const double pi = acos(-1); const int dx[4] = {0,0,1,-1}; const int dy[4] = {1,-1,0,0}; const int N = 1000; int k,num[N+10]; char s[N+10]; string ss; int main(){ #ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin); #endif ios::sync_with_stdio(0),cin.tie(0); cin >> k; cin >> s; int len = strlen(s); rep1(i,0,len-1){ num[s[i]-'a']++; } for (int i = 0;i < 26;i++) if (num[i]%k!=0){ return
cout<<-1<<endl,0; }else{ for (int j = 1;j <= num[i]/k;j++) ss+=((char)(i+'a')); } if (len%k!=0){ return cout<<-1<<endl,0; } for (int i = 1;i <= k;i++) cout<<ss; return 0; }

【Henu ACM Round#24 A】k-String