-
Notifications
You must be signed in to change notification settings - Fork 2
/
10338.cpp
executable file
·76 lines (60 loc) · 1.37 KB
/
10338.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
using namespace::std ;
int main()
{
int datasets ;
cin >> datasets ;
int letters[ 26 ] = { 0 } ;
char input[ 30 ] ;
int prime[ 9 ] = { 2, 3, 5, 7, 11, 13, 17, 19, 23 } ;
int factorial[ 9 ] ;
/* 2 3 5 7 11 13 17 19 23 */
char dealing ;
long long int dealing_number ;
unsigned long int answer ;
for( int i = 1 ; i <= datasets ; i++ )
{
answer = 1 ;
for( int j = 0 ; j < 26 ; j++ )
{
letters[ j ] = 0 ;
}
for( int j = 0 ; j < 9 ; j++ )
{
factorial[ j ] = 0 ;
}
cin >> input ;
for( int j = 0 ; ( dealing = input[ j ] ) != '\0' ; j++ )
{
dealing_number = j + 1 ;
for( int k = 0 ; k < 9 ; k++ )
{
while( dealing_number % prime[ k ] == 0 )
{
factorial[ k ]++ ;
dealing_number /= prime[ k ] ;
}
}
( letters[ static_cast<int>( dealing ) - static_cast<int>( 'A' ) ] )++ ;
dealing_number = letters[ static_cast<int>( dealing ) - static_cast<int>( 'A' ) ] ;
for( int k = 0 ; k < 9 ; k++ )
{
while( dealing_number % prime[ k ] == 0 )
{
factorial[ k ]-- ;
dealing_number /= prime[ k ] ;
}
}
}
for( int j = 0 ; j < 9 ; j++ )
{
while( factorial[ j ] > 0 )
{
answer *= prime[ j ] ;
factorial[ j ]-- ;
}
}
cout << "Data set " << i << ": " << answer << endl ;
}
return 0 ;
}