package cn. mianshi;
public class BinomialEfficiency {
public static void main ( String[ ] args) {
int N= 20 , K= 30 ;
int m;
try {
if ( N>= K) {
m= factor ( N) / ( factor ( K) * factor ( N- K) ) ;
} else {
m= - 1 ;
}
System. out. println ( m) ;
} catch ( Exception e) {
m= - 1 ;
System. out. println ( m) ;
}
}
public static int factor ( int a) {
int out= 1 ;
if ( a>= 1 ) {
for ( int i= 1 ; i<= a; i++ ) {
out*= i;
}
} else {
out= 1 ;
}
return out;
}
}
package cn. mianshi;
public class BinaryStringToZero {
public static void main ( String[ ] args) {
String S= "110101" ;
int a= ByteToDecimal ( S) ;
System. out. println ( a) ;
int num= 0 ;
while ( a!= 0 ) {
if ( a % 2 == 1 ) {
a-- ;
num++ ;
} else {
a = a>> 1 ;
num++ ;
}
}
System. out. println ( num) ;
}
public static int ByteToDecimal ( String S) {
return Integer. valueOf ( S, 2 ) ;
}
}
ackage cn. mianshi;
import java. util. ArrayList;
public class MostFrequencyOccurChar {
public static void main ( String[ ] args) {
String S= "waaahatfutttck" ;
char [ ] ss= new char [ S. length ( ) ] ;
ss= S. toCharArray ( ) ;
int [ ] a= new int [ ss. length] ;
for ( int i= 0 ; i< ss. length; i++ ) {
for ( int j= 0 ; j< ss. length; j++ ) {
if ( ss[ i] == ss[ j] ) {
a[ i] ++ ;
}
}
}
int max = 0 ;
int maxIndex = 0 ;
for ( int i = 0 ; i < a. length; i++ ) {
if ( a[ i] > max) {
max = a[ i] ;
maxIndex = i;
}
}
System. out. println ( S. charAt ( maxIndex) ) ;
for ( int A: a) {
System. out. print ( A+ " " ) ;
}
}
}
package cn. mianshi;
public class DistanceSum {
public static void main ( String[ ] args) {
int [ ] A= { 1 , 3 , - 3 } ;
int [ ] B= new int [ A. length* 2 ] ;
int k= 0 ;
for ( int i= 0 ; i< A. length; i++ ) {
for ( int j= i; j< A. length; j++ ) {
B[ k] = A[ i] + A[ j] + ( j- i) ;
k++ ;
}
}
int max= 0 ;
for ( int i= 0 ; i< B. length; i++ ) {
if ( B[ i] > max) {
max= B[ i] ;
}
}
System. out. println ( max) ;
for ( int a: B) {
System. out. println ( a) ;
}
}
}