根据老哥 可达鸭子 思路写的,没咋验证
#include<iostream> #include<algorithm> #include<string> #include<sstream> #include<set> using namespace std; void Move(string& str) { int len = str.size(); for (int i = 1; i < len; i++) { if (str[i] != '0') { str[0] = str[i]; str[i] = '0'; break; } } } int main() { string n; int m; cin >> n >> m; sort(n.begin(), n.end()); set<string> res; if (n[0] == '0') Move(n); res.insert(n); while (next_permutation(n.begin(), n.end())) { res.insert(n); } int count = 0; int tmp; stringstream ss; for (auto p : res) { ss.clear(); ss << p; ss >> tmp; if (tmp % m == 0) count++; } cout << count; return 0; }
全部评论
(0) 回帖