Ural 1044 Lucky tickets. Easy!

Ural 1044 Lucky tickets. Easy!

注意的是这里的n位数可以以0打头

#include < iostream >
using   namespace  std;

void  f2()
{
     
int  count = 0 ;
     
for ( int  i1 = 0 ; i1 <= 9 ; i1 ++ )
     
for ( int  i2 = 0 ; i2 <= 9 ; i2 ++ )
             
if (i1 == i2)count ++ ;
     cout
<< count << endl;
}

void  f4()
{
     
int  count = 0 ;
     
for ( int  i1 = 0 ; i1 <= 9 ; i1 ++ )
     
for ( int  i2 = 0 ; i2 <= 9 ; i2 ++ )
     
for ( int  i3 = 0 ; i3 <= 9 ; i3 ++ )
     
for ( int  i4 = 0 ; i4 <= 9 ; i4 ++ )
             
if (i1 + i2 == i3 + i4)count ++ ;
     cout
<< count << endl;
}

void  f6()
{
     
int  count = 0 ;
     
for ( int  i1 = 0 ; i1 <= 9 ; i1 ++ )
     
for ( int  i2 = 0 ; i2 <= 9 ; i2 ++ )
     
for ( int  i3 = 0 ; i3 <= 9 ; i3 ++ )
     
for ( int  i4 = 0 ; i4 <= 9 ; i4 ++ )
     
for ( int  i5 = 0 ; i5 <= 9 ; i5 ++ )
     
for ( int  i6 = 0 ; i6 <= 9 ; i6 ++ )
             
if (i1 + i2 + i3 == i5 + i4 + i6)count ++ ;
     cout
<< count << endl;
}

void  f8()
{
     
int  count = 0 ;
     
for ( int  i1 = 0 ; i1 <= 9 ; i1 ++ )
     
for ( int  i2 = 0 ; i2 <= 9 ; i2 ++ )
     
for ( int  i3 = 0 ; i3 <= 9 ; i3 ++ )
     
for ( int  i4 = 0 ; i4 <= 9 ; i4 ++ )
     
for ( int  i5 = 0 ; i5 <= 9 ; i5 ++ )
     
for ( int  i6 = 0 ; i6 <= 9 ; i6 ++ )
     
for ( int  i7 = 0 ; i7 <= 9 ; i7 ++ )
     
for ( int  i8 = 0 ; i8 <= 9 ; i8 ++ )
             
if (i1 + i2 + i3 + i4 == i5 + i7 + i6 + i8)count ++ ;
     cout
<< count << endl;
}

int  main()
{
    
int  n;
    cin
>> n;
    
if (n == 2 )f2();
    
else   if (n == 4 )f4();
    
else   if (n == 6 )f6();
    
else   if (n == 8 )f8();
    
    system(
" pause " );
    
return   0 ;
}

你可能感兴趣的:(Ural 1044 Lucky tickets. Easy!)