暴力,next_permutation函数用于枚举出下一个排列。sscanf函数用于将字符串转化成数字。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int n,len,ans;
 6 long long x,t;
 7 char s[15];
 8 int main()
 9 {
10     scanf("%d",&n);
11     for(int i=1;i<=n;i++)
12       {
13         ans=0;
14         scanf("%s%lld",s,&x);
15         len=strlen(s);
16         sort(s,s+len);
17         sscanf(s,"%lld",&t);
18         if(!(t%x))ans++;
19         while(next_permutation(s,s+len))
20           {
21               sscanf(s,"%lld",&t);
22               if(!(t%x))ans++;
23           }
24         printf("%d\n",ans);
25       }
26     return 0;
27 }

 

相关文章:

  • 2022-12-23
  • 2021-07-28
  • 2021-06-14
  • 2022-01-29
  • 2021-06-03
  • 2021-12-26
  • 2022-02-18
  • 2021-09-29
猜你喜欢
  • 2018-03-15
  • 2021-07-16
  • 2021-09-10
  • 2021-08-20
  • 2022-12-23
相关资源
相似解决方案