-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstanzeMagzine.java
More file actions
72 lines (64 loc) · 1.7 KB
/
ConstanzeMagzine.java
File metadata and controls
72 lines (64 loc) · 1.7 KB
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
import java.util.Scanner;
public class ConstanzeMagzine
{
static int[] fact = new int[ 100000 ];
static int MOD = 1000000007;
static
{
fact[0] = 1;
}
public static void main( String[] args )
{
Scanner s = new Scanner( System.in );
String str = s.nextLine();
int n = str.length();
int t = 0;
int count = 1;
for( int i = 1; i < n; i++ )
{
char c = str.charAt( i );
if( c == 'm' || c == 'w' )
{
t = 0;
count = 0;
break;
}
else if( ( c == 'n' && 'n' == str.charAt( i - 1 ) ) || ( c == 'u' && 'u' == str.charAt( i - 1 ) ) )
{
count++;
}
else if( ( str.charAt( i - 1 ) == 'u' && c != 'u' ) || ( str.charAt( i - 1 ) == 'n' && c != 'n' ) )
{
if( count > 1 )
t += getTotalPermutataions( count );
count = 1;
}
}
if( count >= 1 )
t += getTotalPermutataions( count );
if(count==0)
t=0;
System.out.println( t );
}
private static int getTotalPermutataions( int count )
{
int t = 0;
for( int i = 0; i <= count / 2; i++ )
{
int ts = count - i;
t += fact( ts ) / ( fact( i ) * fact( ts - i ) );
}
return t;
}
private static int fact( int n )
{
if( fact[n] != 0 )
return fact[n];
for( int i = 1; i <= n; i++ )
{
fact[i] = i * fact[i - 1];
fact[i] = fact[i] % MOD;
}
return fact[n];
}
}