[Swust 549]--变位词(vector水过)

Time limit(ms): 1000        Memory limit(kb): 65535
 
Description

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

 

Input

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

 
Output

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

 

Sample Input
7
asdfg
asdgf
asdfg
dsafg
xcvcv
gfdsa
tyuv
asd

Sample Output
asdfg
asdgf
dsafg
gfdsa
4

 
 
 
嗯~~没什么好说的水题,运用vector直接水过 ,Orz~~
代码如下:
 1 #include <iostream>
 2 #include <string>
 3 #include <vector>
 4 #include <algorithm>
 5 using namespace std;
 6 bool judge(string a,string b){
 7     sort(a.begin(),a.end());
 8     sort(b.begin(),b.end());
 9     return a==b?true:false;
10 }
11 int main(){
12     string a,b;
13     vector<string> mpt;
14     vector<string>::iterator it;
15     int n,i;
16     cin>>n>>a;
17     for(i=0;i<n;i++){
18         cin>>b;
19         if(judge(a,b)) mpt.push_back(b);
20     }
21     sort(mpt.begin(),mpt.end());
22     for(it=mpt.begin();it!=mpt.end();it++)
23         cout<<*it<<endl;
24     cout<<mpt.size()<<endl;
25     return 0;
26 }
View Code

 

转载于:https://www.cnblogs.com/zyxStar/p/4580434.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值