To find the number of rows that appear in the next row

Source: Internet
Author: User

Topic:

To give an example:

Value: 0,1,2,3,4,5,6,7,8,9

Allocation: 6,2,1,0,0,0,1,0,0,0

0 appeared in the lower row 6 times, 1 in the lower row appeared 2 times.

2 appeared in the next row, ...

And so on



#include <iostream>
using namespace Std;
#define LEN 10
Class NUMBERTB
{
Private
int Top[len];
int Bottom[len];
BOOL success;
Public
NUMBERTB ();
int* Getbottom ();
void Setnextbottom ();
int getfrequency (int num);
};
NUMBERTB::NUMBERTB ()
{
Success = false;
Format Top
for (int i = 0; i < len;i++)
{
Top[i] = i;
}


}
int* Numbertb::getbottom ()
{
int i = 0;
while (!success)
{
i++;
Setnextbottom ();
}
return bottom;
}
Set Next Bottom
void Numbertb::setnextbottom ()
{
bool ReB = true;
for (int i = 0; i < len; i++)
{
int frequecy = getfrequency (i);
if (bottom[i]! = frequecy)
{
Bottom[i] = Frequecy;
ReB = false;
}
}
Success = ReB;
}
Get frequency in Bottom
int numbertb::getfrequency (int num)//Here num refers to the number of rows I
{
int count = 0;
for (int i = 0; i < len; i++)
{
if (bottom[i] = = num)
count++;
}
Return count;//count that corresponds to frequency
}


int main ()
{
NUMBERTB NTB;
int* result = Ntb.getbottom ();
for (int i = 0; i < len; i++)
{
cout << *result++ << Endl;
}
System ("pause");
return 0;
}

To find the number of rows that appear in the next row

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.