日本搞逼视频_黄色一级片免费在线观看_色99久久_性明星video另类hd_欧美77_综合在线视频

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > 互聯網 > Codeforces Round #135 (Div. 2)---A. k-String

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

來源:程序員人生   發布時間:2014-11-15 03:46:59 閱讀次數:3465次

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個串,問是不是能由k個相同的串聯接而成。

用STL里的map。掃1遍,分別記錄每一個字符的個數,在判斷所有的字符是不是是k的倍數,若不是,則輸出⑴;否則,遍歷順次map,每一個字符輸出(總個數)/k個,然后重復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; }


生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 色免费观看 | 中文字幕一区在线 | 国产一区二区三区四区五区tv | 亚洲综合字幕 | av免费网址| 欧美成人免费在线 | 国产色女 | av成人免费 | 中文字幕日韩专区 | 国产精品美女久久久久 | 亚洲高清在线视频 | 免费看的一级毛片 | 久久久免费观看视频 | 国产精品呻吟久久av凹凸 | 午夜精品久久久久久久久久蜜桃 | 欧美电影一区二区 | 婷婷成人基地 | 欧美日本韩国在线 | 日韩毛片在线看 | 欧美视频一区二区 | 国产精品视频一区二区免费不卡 | 综合久久久久久久 | 亚洲精品久久久久久动漫 | 精品色综合 | 日韩成人在线视频 | 欧美成人午夜电影 | 热久久91| 二区在线观看 | 色综合社区 | 成人97精品毛片免费看 | 久久在线免费视频 | 精品久久99 | 高清不卡一区二区 | 久久精品成人一区二区三区蜜臀 | 久久久久久国产精品 | 在线观看毛片网站 | 国产精品av在线 | 国产精品免费一区 | 麻豆乱码国产一区二区三区 | 日本 欧美 国产 | 国产精品成人国产乱一区 |