刷题006--

给你10分钟时间,根据上排给出十个数,在其下排填出对应的十个数  
要求下排每个数都是先前上排那十个数在下排出现的次数。  
上排的十个数如下:  
【0,1,2,3,4,5,6,7,8,9】

#include<iostream>

using namespace std;
#define len 20
class numberTB {
private:
int top[len];
int bottom[len];
bool success;
int firstNumber;
public:
numberTB(int firstnumber);
int* getBottom();
void setnextBottom();
int getFrequency(int num);
};
numberTB::numberTB(int firstnumber) {
firstNumber = firstnumber;
success = false;
for (int i = 0; i < len; i++) {
top[i] = i+firstNumber;
}
}
int* numberTB::getBottom() {
int i = 0;
while (!success) {
i++;
setnextBottom();
}
return bottom;
}
void numberTB::setnextBottom() {
bool reB = true;
for (int i = 0; i < len; i++) {
int frequency = getFrequency(top[i]);
if (bottom[i] != frequency) {
bottom[i] = frequency;
reB = false;
}
success = reB;
}
}
int numberTB::getFrequency(int num) {
int count = 0;
for (int i = 0; i < len; i++) {
if (bottom[i] == num)  count++;
}
return count;
}
int main() {
int firstnumber = 10;
numberTB numbertb(firstnumber);
int* result = numbertb.getBottom();
for (int i = 0; i < len; i++) {
cout << *result++ << endl;
}
return 0;

}


题目相当绕,要是面试问这种题我肯定呆十分钟什么也想不出来吧。。。过程就是不断回溯检测,当然也是看了答案才懂的。。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值