简单有趣#113:越聚越多【难度:1级】:
答案1:
namespace myjinxin
{
using System;
public class Kata
{
public bool NumberIncreasing ( int n) {
if ( n- 59049 >= 0 & amp; & amp; ( ( n- 59049 ) ) % 5 == 0 )
{
return true ;
}
else if ( n- 19683 > 0 & amp; & amp; ( ( n- 19683 ) ) % 5 == 0 )
{
return true ;
}
else if ( n- 6561 > 0 & amp; & amp; ( ( n- 6561 ) ) % 5 == 0 )
{
return true ;
}
else if ( n- 2187 > 0 & amp; & amp; ( ( n- 2187 ) ) % 5 == 0 )
{
return true ;
}
else if ( n- 729 > 0 & amp; & amp; ( ( n- 729 ) ) % 5 == 0 )
{
return true ;
}
else if ( n- 243 > 0 & amp; & amp; ( ( n- 243 ) ) % 5 == 0 )
{
return true ;
}
else if ( n- 81 > 0 & amp; & amp; ( ( n- 81 ) ) % 5 == 0 )
{
return true ;
}
else if ( n- 27 > 0 & amp; & amp; ( ( n- 27 ) ) % 5 == 0 )
{
return true ;
}
else if ( n- 9 > 0 & amp; & amp; ( ( n- 9 ) ) % 5 == 0 )
{
return true ;
}
else if ( ( n- 3 ) % 5 == 0 ) {
return true ;
}
else if ( ( n- 1 ) % 5 == 0 ) {
return true ;
}
return false ;
}
}
}
答案2:
namespace myjinxin
{
using System;
public class Kata
{
public bool NumberIncreasing ( int n)
{
if ( n % 5 == 0 ) return false ;
if ( n > 22 ) return true ;
return ! ( n % 5 == 2 || n == 4 ) ;
}
}
}
答案3:
namespace myjinxin
{
using System;
public class Kata
{
public bool NumberIncreasing ( int n)
{
if ( n % 5 == 0 ) return false ;
if ( n > 22 ) return true ;
return ( n % 5 == 2 || n == 4 ) ? false : true ;
}
}
}
答案4:
using System;
using System. Collections. Generic;
using System. Linq;
using System. Text;
namespace myjinxin
{
using System;
public class Kata
{
public bool NumberIncreasing ( int n) {
HashSet< int > A = new HashSet < int > ( ) { 2 , 4 , 7 , 12 , 17 , 22 } ;
return ( ! ( A. Contains ( n) ) & amp; & amp; ( n % 5 != 0 ) ) ;
}
}
}
答案5:
namespace myjinxin
{
using System;
public class Kata
{
public bool NumberIncreasing ( int n)
{
if ( n == 1 || n == 3 ) return true ;
if ( n - 5 <= 0 ) return false ;
if ( ( n - 1 ) % 5 == 0 ) return true ;
int res = 1 ;
while ( res < n) { res * = 3 ; if ( ( n - res) % 5 == 0 ) return true ; }
if ( res == n || res - 5 == n) return true ;
return false ;
}
}
}
答案6:
namespace myjinxin
{
using System;
public class Kata
{
public bool NumberIncreasing ( int n) {
while ( n > 1 )
{
if ( n % 5 == 1 ) return true ;
if ( n % 3 == 0 ) n / = 3 ; else n - = 5 ;
}
return ( n == 1 ) ? true : false ;
}
}
}
答案7:
namespace myjinxin
{
using System;
using System. Linq;
public class Kata
{
public bool NumberIncreasing ( int n) = > n % 5 != 0 & amp; & amp; ! new [ ] { 2 , 4 , 7 , 12 , 17 , 22 } . Contains ( n) ;
}
}
答案8:
namespace myjinxin
{
using System;
public class Kata
{
public bool NumberIncreasing ( int n) {
if ( PowOf3 ( n) ) return true ;
while ( n- 5 >= 1 ) {
n- = 5 ;
if ( PowOf3 ( n) ) return true ;
}
return n== 1 ;
}
bool PowOf3 ( int n) = > ( double ) Math. Log ( n, 2 ) / Math. Log ( 3 , 2 ) % 1 == 0 ;
}
}
答案9:
using System;
using System. Linq;
namespace myjinxin
{
public class Kata
{
public bool NumberIncreasing ( int n)
{
bool result = false ;
if ( n > 0 )
{
if ( n == 1 )
result = true ;
else if ( ( ( Math. Log ( n) / Math. Log ( 3 ) ) % 1 == 0 ) || ( ( n - 1 ) % 5 == 0 ) )
result = true ;
else if ( n. ToString ( ) . Sum ( c = > c - '0' ) % 3 == 0 )
result = NumberIncreasing ( n/ 3 ) ;
else
result = NumberIncreasing ( n- 5 ) ;
}
return result;
}
}
}
答案10:
namespace myjinxin
{
using System;
using System. Collections. Generic;
public class Kata
{
private List< int > increased = new List < int > { 0 , 1 } ;
public bool NumberIncreasing ( int n)
{
while ( increased. Count <= n)
{
increased. Add ( - 1 ) ;
}
if ( increased[ n] == - 1 )
{
increased[ n] = n % 3 == 0 & amp; & amp; NumberIncreasing ( n / 3 ) || n > 5 & amp; & amp; NumberIncreasing ( n - 5 ) ? 1 : 0 ;
}
return increased[ n] != 0 ;
}
}
}