[算法练习]根据上排给出十个数,在其下排填出对应的十个数
2012-05-15 16:19
357 查看
View Code
#include <iostream> using namespace std; const int SIZE=10; int getFrequency(int index,int* bottom) { int count=0; for(int i=0;i<SIZE;++i) { if(bottom[i]==index) count++; } return count; } void Calc(const int* Upper,int* bottom) { bool isChange=true; int loop_count=0; while(isChange) { loop_count++; isChange=false; for(int i=0;i<SIZE;++i) { int fre=getFrequency(i,bottom); if(bottom[i]!=fre) { bottom[i]=fre; isChange=true; } } } for(int i=0;i<SIZE;++i) cout <<bottom[i]<<" "; cout <<endl; cout <<"The number of loop is "<<loop_count<<endl; } int main() { int Upper[SIZE]; int Bottom[SIZE]; for(int i=0;i<SIZE;++i) { Upper[i]=i; Bottom[i]=0; } Calc(Upper,Bottom); return 0; }
相关文章推荐
- 【练习】10 分钟时间,根据上排给出十个数,在其下排填出对应的十个数
- 算法题24 根据上排给出十个数,在其下排填出对应的十个数
- 每天学习一算法系列(7) (根据上排给出十个数,在其下排填出对应的十个数)
- 每天学习一算法系列(7) (根据上排给出十个数,在其下排填出对应的十个数)
- 每天一算法(根据上排给出十个数,在其下排填出对应的十个数)
- 算法题24 根据上排给出十个数,在其下排填出对应的十个数
- 6.给你10 分钟时间,根据上排给出十个数,在其下排填出对应的十个数
- 给你10分钟时间,根据上排给出十个数,在其下排填出对应的十个数
- 给你10分钟时间,根据上排给出十个数,在其下排填出对应的十个数 要求下排每个数都是先前上排那十个数在下排出现的次数
- 根据上排给出十个数,在其下排填出对应的十个数 要求下排每个数都是先前上排那十个数在下排出现的次数
- [面试tx] 根据上排给出十个数,在其下排填出对应的十个数
- IT公司100题-6-根据上排给出十个数,在其下排填出对应的十个数
- [面试tx] 根据上排给出十个数,在其下排填出对应的十个数
- 根据上排给出十个数,在其下排填出对应的十个数
- 根据上排给出十个数,在其下排填出对应的十个数
- 根据上排给出十个数,在其下排填出对应的十个数
- 【编程题目】给你 10 分钟时间,根据上排给出十个数,在其下排填出对应的十个数
- 每天三道冲刺工作--根据上排给出十个数,在其下排填出对应的十个数
- 微软100题(6) 根据上排给出十个数,在其下排填出对应的十个数
- 递推: 给你10分钟时间,根据上排给出十个数,在其下排填出对应的十个数 要求下排每个数都是先前上排那十个数在下排出现的次数