解题思路:
1.输入s
2.用set保存所有长度为8的s的子串 //方便判断
3.输入n,循环n次:
1).输入密码串s
2).排序s,方便用库函数遍历所有排列组合
3).遍历时,如果st中有这个字符串则ans++
4.输出ans
注意事项:
参考代码:
#include<bits/stdc++.h> using namespace std; string s; set<string> st; int main(){ cin>>s; int n=s.length(); for(int i=0;i+7<n;i++)st.insert(s.substr(i,8));//set长度为8的子串 cin>>n; int ans=0; while(n--){ cin>>s; sort(s.begin(),s.end()); do{ if(st.count(s))ans++; }while(next_permutation(s.begin(),s.end())); } cout<<ans<<endl; }
0.0分
4 人评分
简单的a+b (C语言代码)浏览:573 |
C语言程序设计教程(第三版)课后习题8.5 (C语言代码)浏览:936 |
字符逆序 (C语言代码)浏览:460 |
整除问题 (C语言代码)浏览:526 |
C语言训练-8除不尽的数 (C语言代码)浏览:1398 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:998 |
判定字符位置 (C++代码)浏览:668 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:447 |
【密码】 (C语言代码)浏览:502 |
C语言训练-求s=a+aa+aaa+aaaa+aa...a的值 (C语言代码)浏览:705 |