ZZULIOJ--1239: K-String

Time limit: 1 Sec memory limit: 128 MB
submitted: 422 solution: 165
[Status] [submitted] [proposition al: External Import]
Title Description
If a string can be connected by the same character string consisting of k, then this character string called K-string example: aabaabaabaab string that is 1-string, is 2-string, also 4-string. Obviously, for any string, it is a
1-String.
Now give a string S (containing only lowercase letters) and an integer K, your task is to rearrange the S, turned it into a K -String.

Input
Input test group comprising N instances, each instance representing two lines, the first line is an integer K (1 <= K <= 1000). The second line is the length between 1-1000 string of the SS.

Output
each output row for example, is determined by the string S can then rearranged into a K-String, can be output if Yes, otherwise, outputs No.

Sample input Copy
2
2
aabbcc
2
AAAC
sample output Copy
Yes
No
Source / Category
2013 school competition

#include<bits/stdc++.h>
using namespace std;
int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		int n;
		scanf("%d",&n);
		int v[26];
		memset(v,0,sizeof(v));
		char c[2000];
		scanf("%s",c);
		for(int i=0;i<strlen(c);i++){
			int a=c[i]-'a';
			v[a]++;
		}
		int ans=0;
		for(int i=0;i<26;i++){
			if(v[i]%n==1)
			{
				ans=1;
			}
		}
		if(ans==1)
		printf("No\n");
		else
		printf("Yes\n");
	}
	return 0;
}

Published 16 original articles · won praise 1 · views 294

Guess you like

Origin blog.csdn.net/CoIorful/article/details/104119342