题解:CF1971B Different String

原地址:这里

题意

给出字符串 \(s\),询问更改 \(s\) 的排列顺序后与原来的 \(s\) 是否不同,不同输出 YES,否则输出 NO

思路

只要判断字符串中含有不同的字符即可。

代码

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int t;
	scanf("%d",&t);
	while(t--){
		char s[15];
		scanf("%s",s);
		int flag=1;
		for(int i=1;s[i]!='\0';i++){
			if(s[i]!=s[0]){
				swap(s[i],s[0]);
				printf("YES\n%s\n",s);
				flag=0;
				break;
			} 
		}
		if(flag) printf("NO\n");
	}
	return 0;
}
posted @ 2024-08-13 21:06  volatiles  阅读(17)  评论(0)    收藏  举报