QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457530#8829. Aibohphobiaucup-team1004#WA 1ms3624kbC++14845b2024-06-29 13:11:482024-06-29 13:14:12

Judging History

你现在查看的是最新测评结果

  • [2024-06-29 13:14:12]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3624kb
  • [2024-06-29 13:11:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int t[26],n,T;
char str[1000010];
bool chk1()
{
	for(int i=0;i<26;i++)
		if(t[i]==1)
		{
			puts("YES");
			putchar(i+'a'),t[i]=0;
			for(int j=0;j<26;j++)
				while(t[j]--) putchar(j+'a');
			puts("");
			return 1;
		}
	return 0;
}
bool chk2()
{
	int cnt=0;
	for(int i=0;i<26;i++) cnt+=(t[i]>0);
	return cnt==2;
}
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%s",str);
		n=strlen(str);
		for(int i=0;i<26;i++) t[i]=0;
		for(int i=0;i<n;i++) t[str[i]-'a']++;
		if(chk1()) continue;
		else if(chk2()) {puts("NO");continue;}
		for(int i=0;i<26;i++)
			if(t[i])
			{
				puts("YES");
				putchar(i+'a'),t[i]--;
				for(int j=0;j<26;j++)
					if(j!=i) while(t[j]--) putchar(j+'a');
				while(t[i]--) putchar(i+'a');
				break;
			}
		puts("");
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3624kb

input:

5
a
sos
abba
icpc
tenet

output:

YES
a
YES
oss
NO
YES
iccp
YES
neett

result:

ok Correct (5 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3616kb

input:

18
qnx
oooo
tvttj
zzzzz
pvlne
iijt
hjhjj
loo
hh
uq
mgvgv
ewwe
iii
kykk
o
mmumm
aetvv
xntl

output:

YES
nqx
YES
oooo
YES
jtttv
YES
zzzzz
YES
elnpv
YES
jiit
NO
YES
loo
YES
hh
YES
qu
YES
mggvv
NO
YES
iii
YES
ykkk
YES
o
YES
ummmm
YES
aetvv
YES
lntx

result:

wrong answer Some prefix is a palindrome (test case 2)