swustoj变位词(0549)

输入N和一个要查找的字符串,以下有N个字符串,我们需要找出其中的所有待查找字符串的变位词(例如eat,eta,aet就是变位词)按字典序列输出,并且输出总数目

Description

第一行:N(代表共有N个字符串属于被查找字符串) (N<=50) 第二行:待查找的字符串(不大于10个字符) 以下N行:被查找字符串(不大于10个字符)

Input

按字典序列输出在被查找字符串中待查找字符串的所有变位词 每行输出一个 输出完成后输出总数目

Output
1
2
3
4
5
6
7
8
9
7
asdfg
asdgf
asdfg
dsafg
xcvcv
gfdsa
tyuv
asd
Sample Input
1
2
3
4
5
asdfg
asdgf
dsafg
gfdsa
4
Sample Output
/*水题:直接暴力可以过*/


#include <stdio.h>
#include <string.h>
#include<iostream>
#include<stack>
#include<algorithm>
using namespace std;

struct node
{
	char str[15];
};
node a[55], b[55];

bool cmp1(char a, char b)
{
	return a < b;
}

bool cmp2(node xx, node yy)
{
	if (strcmp(xx.str, yy.str) < 0)
		return 1;
	else
		return 0;
}

int main()
{
	int n;
	char s[15];
	while (cin >> n)
	{
		//getchar();
		cin >> s;
		sort(s, s + strlen(s), cmp1);

		//cout << s << endl;
		for (int i = 0; i < n; i++)
		{
			scanf("%s", a[i].str);
		}
		sort(a, a + n, cmp2);
		int k = 0;
		int ans = 0;
		for (int i = 0; i < n; i++)
		{
			node temp;
			temp = a[i];
			sort(temp.str, temp.str + strlen(temp.str), cmp1);
			if (strcmp(temp.str, s) == 0)
			{
				b[k++] = a[i];
				ans++;
			}
		}
		for (int i = 0; i < k; i++)
		{
			cout << b[i].str << endl;
		}
		cout << ans << endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值