In snoj 1019, the idea of using the class version is very clear ......

Source: Internet
Author: User

// By bodesmile

// Start:

// Algorithm:

// Note:

# Include <iostream>

Using namespace STD;

Class base_12;

Class base_16

{

Public:

Base_16 (int A, int B, int C, int D)

{

Num [0] = D;

Num [1] = C;

Num [2] = B;

Num [3] =;

}

Void b16_add ()

{

If (Num [0] <15)

{

Num [0] ++;

}

Else if (Num [1] <15)

{

Num [0] = 0;

Num [1] ++;

}

Else if (Num [2] <15)

{

Num [0] = 0;

Num [1] = 0;

Num [2] ++;

}

Else

{

Num [0] = 0;

Num [1] = 0;

Num [2] = 0;

Num [3] ++;

}

}

 

Friend bool comp12and16 (int I, base_12 num12, base_16 num16 );

PRIVATE:

Int num [4];

};

Class base_12

{

Public:

Base_12 (int A, int B, int C, int D)

{

Num [0] = D;

Num [1] = C;

Num [2] = B;

Num [3] =;

}

Void b12_add ()

{

If (Num [0] <11)

{

Num [0] ++;

}

Else if (Num [1] <11)

{

Num [0] = 0;

Num [1] ++;

}

Else if (Num [2] <11)

{

Num [0] = 0;

Num [1] = 0;

Num [2] ++;

}

Else

{

Num [0] = 0;

Num [1] = 0;

Num [2] = 0;

Num [3] ++;

}

}

Friend bool comp12and16 (int I, base_12 num12, base_16 num16 );

PRIVATE:

Int num [4];

};

Bool comp12and16 (int I, base_12 num12, base_16 num16)

{

Int temp = 0;

Temp + = (I % 10 );

I/= 10;

Temp + = (I % 10 );

I/= 10;

Temp + = (I % 10 );

I/= 10;

Temp + = I;

Int temp1, temp2;

Temp1 = num12.num [0] + num12.num [1] + num12.num [2] + num12.num [3];

If (temp! = Temp1)

Return false;

Temp2 = num16.num [0] + num16.num [1] + num16.num [2] + num16.num [3];

If (temp! = Temp2)

Return false;

Return true;

}

Int main ()

{

//

Base_16 num16 );

Base_12 num12 (0, 6, 11, 4 );

Int I;

For (I = 1000; I <10000; I ++)

{

If (comp12and16 (I, num12, num16 ))

Cout <I <Endl;

Num16.blob _ add ();

Num12.b12 _ add ();

}

Return 0;

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.