fork(1) download
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<math.h>
  4. #include<iostream>
  5. #include<string>
  6. #include<stdlib.h>
  7. #include<vector>
  8. #include<stack>
  9. #include<queue>
  10. #include<set>
  11. #include<map>
  12. #include<algorithm>
  13. using namespace std;
  14. #define maxv(A,B) (A>B?A:B)
  15. #define minv(A,B) (A>B?B:A)
  16. #define inf 2147483647
  17. #define pi (2*acos(0.0))
  18. #define eps 1e-9
  19. int gcd(int a,int b) {return (b==0?a:gcd(b,a%b));}
  20. int lcm(int a,int b) {return (a*(b/gcd(a,b)));}
  21. int fx[]={0,0,1,-1};
  22. int fy[]={-1,1,0,0};
  23.  
  24. int main()
  25. {
  26. //freopen("input.txt","r",stdin);
  27. //freopen("output.txt","w",stdout);
  28. int num_word,i,t,ca=1,l;
  29. string str,s2;
  30. cin>>t;
  31. while(t--)
  32. {
  33. map<string,int> m;
  34. cin>>num_word;
  35. for(i=0;i<num_word;i++)
  36. {
  37. cin>>str;
  38. l=str.size();
  39. if(l>3)
  40. sort(str.begin()+1,str.end()-1);
  41. ++m[str];
  42. }
  43. int query,ans=1,ll,jj;
  44. char s1[100005];
  45. cin>>query;
  46. printf("Case %d:\n",ca++);
  47. getchar();
  48. for(jj=1;jj<=query;jj++)
  49. {
  50. ans=1;
  51. gets(s1);
  52. str=s1;
  53. ll=str.size();
  54. i=0;
  55. while(i<ll)
  56. {
  57. s2="";
  58. while(i<ll&&str[i]!=' ')
  59. {
  60. s2=s2+str[i++];
  61. }
  62. while(str[i]==' '&&i<ll)
  63. i++;
  64.  
  65. l=s2.size();
  66. if(l==0) {ans*=1; continue;}
  67. if(l>3)
  68. sort(s2.begin()+1,s2.end()-1);
  69. ans*=m[s2];
  70. }
  71. printf("%d\n",ans);
  72. }
  73. }
  74. return 0;
  75. }
Success #stdin #stdout 0s 3460KB
stdin
16
8
baggers
beggars
in
the
blowed
bowled
barn
bran
1
beggars bowled in the barn
3
a
b
c
1
a b c
2
a
b
1
a b c
3
abczzz
AbcdZZ
lfdpPSlslaSPApSWlwLWWWsssss
3
abcdef

AZbcdZ abczzz lfdpPSlslaSPApSWlwLWWWsssss lfdpPSlslaSAPpSWlwLWWWsssss 
3
abcd
acbd
xyz
2
      
abcd xyz
3
abcd
acbd
xyz
3
              
        a     afdd hghnh
abcd xyz
2
BD
Sle
2
N
 Sle
2
abc
gbc
3
abc abc abc
gbc gbc gbc
abc gbc
8
baggers
beggars
in
the
blowed
bowled
barn
bran
1
beggars bowled in the barn
3
a
b
c
1
a b c
2
a
b
1
a b c
3
abczzz
AbcdZZ
lfdpPSlslaSPApSWlwLWWWsssss
3
abcdef

AZbcdZ abczzz lfdpPSlslaSPApSWlwLWWWsssss lfdpPSlslaSAPpSWlwLWWWsssss 
3
abcd
acbd
xyz
2
      
abcd xyz
3
abcd
acbd
xyz
3
              
        a     afdd hghnh
abcd xyz
2
BD
Sle
2
N
 Sle
2
abc
gbc
3
abc abc abc
gbc gbc gbc
abc gbc
stdout
Case 1:
8
Case 2:
1
Case 3:
0
Case 4:
0
1
1
Case 5:
1
2
Case 6:
1
0
2
Case 7:
0
1
Case 8:
1
1
1
Case 9:
8
Case 10:
1
Case 11:
0
Case 12:
0
1
1
Case 13:
1
2
Case 14:
1
0
2
Case 15:
0
1
Case 16:
1
1
1