兄弟单词

 1 #include<iostream>
 2 #include<string>
 3 #include<vector>
 4 #include<algorithm>
 5 using namespace std;
 6 bool isbrother(string str1, string str2)
 7 {
 8     if (str1.size() == str2.size())
 9     {
10         for (int i = 0; i<str1.size(); i++)
11         {
12             int n;
13             n = str2.find(str1[i]);
14             if (n == -1)
15             {
16                 return false;
17             }
18             else
19             {
20                 str2[n] = '0';
21             }
22 
23 
24         }
25         return true;
26     }
27     return false;
28 }
29 int main()
30 {
31     int n;
32     while (cin >> n)
33     {
34         vector<string> strings;
35         while (n)
36         {
37             string stemp;
38             cin >> stemp;
39             strings.push_back(stemp);
40             n--;
41         }
42         string f_string;
43         cin >> f_string;
44         int m;
45         cin >> m;
46         cin.clear();
47         vector<string>b_strings;
48         for (int i = 0; i<strings.size(); i++)
49         {
50             if (strings[i] == f_string)
51             {
52                 continue;
53             }
54             else
55             {
56                 if (isbrother(f_string, strings[i]))
57                 {
58                     b_strings.push_back(strings[i]);
59                 }
60             }
61         }
62         sort(b_strings.begin(), b_strings.end());
63         cout << b_strings.size() << endl;
if(m<=b_strings.size())
cout<<b_strings[m-1]<<endl;
64 65 66 } 67 }

转载于:https://www.cnblogs.com/ranranblog/p/5660556.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值