多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國(guó)內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁(yè) > 互聯(lián)網(wǎng) > Codeforces Round #135 (Div. 2)---A. k-String

Codeforces Round #135 (Div. 2)---A. k-String

來(lái)源:程序員人生   發(fā)布時(shí)間:2014-11-15 03:46:59 閱讀次數(shù):3460次

k-String
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.

You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string sin such a way that the resulting string is a k-string.

Input

The first input line contains integer k (1?≤?k?≤?1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1?≤?|s|?≤?1000, where |s| is the length of string s.

Output

Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.

If the solution doesn't exist, print "" (without quotes).

Sample test(s)
input
2 aazz
output
azaz
input
3 abcabcabz
output





解題思路:給1個(gè)串,問是不是能由k個(gè)相同的串聯(lián)接而成。

用STL里的map。掃1遍,分別記錄每一個(gè)字符的個(gè)數(shù),在判斷所有的字符是不是是k的倍數(shù),若不是,則輸出⑴;否則,遍歷順次map,每一個(gè)字符輸出(總個(gè)數(shù))/k個(gè),然后重復(fù)k次便可。





AC代碼:

#include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <vector> #include <queue> #include <set> #include <map> #include <string> #include <math.h> #include <stdlib.h> #include <time.h> using namespace std; #define INF 0x7fffffff map<char, int> m; int main() { #ifdef sxk freopen("in.txt","r",stdin); #endif int n; string s; while(scanf("%d",&n)!=EOF) { cin>>s; int len = s.size(); for(int i=0; i<len; i++) m[s[i]] ++; map<char, int>::iterator it; int flag = 1; for(it=m.begin(); it!=m.end(); it++){ if(it->second % n){ flag = 0; break; } } if(!flag) printf("⑴ "); else{ for(int j=0; j<n; j++){ for(it=m.begin(); it!=m.end(); it++){ for(int i=1; i<=it->second/n; i++) printf("%c", it->first); } } printf(" "); } } return 0; }


生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 欧美日韩中文国产一区二区三区 | 国产片自拍 | 成人在线视频网 | 秋霞麻豆 | 国产成人一区二区三区在线播放 | 最近中文字幕无吗高清网 | 欧美视频一级 | 最色网址 | 欧美日韩精品一区二区三区视频在线 | 美国全免费特一级毛片 | 国产欧美日韩综合精品一区二区三区 | 在线观看一区二区三区四区 | 欧美成人精品一区二区 | 一区二区三区视频在线观看 | 亚洲特黄大黄一级毛片 | 亚洲午夜a| 亚洲精品国产一区二区三 | 国产毛片片精品天天看视频 | 日韩久久综合 | 成zzzwww日本免费 | 亚洲国产天堂久久综合9999 | 中文字幕在线观看一区 | 女人18毛片a级毛片一区二区 | 久久伊人成人 | 性一交一乱一伦一色一情 | 国产中文欧美 | 免费看一级毛片欧美 | 色吊丝中文字幕 | 国产午夜免费一区二区三区 | 中文字幕亚洲一区二区三区 | 午夜美女影院 | 日韩三级免费 | 欧美一级高清片在线 | 久久久久久综合 | xxxx性欧美高清 | 久久久高清日本道免费观看 | 亚洲综合图片 | 欧美xxxxhd| 17videosex性欧美 | 国产亚洲欧洲国产综合一区 | 女人l8毛片a一级毛片免费 |