2019独角兽企业重金招聘Python工程师标准>>>
/*=====================================================*\第6题(数组)腾讯面试题: 给你10分钟时间,根据上排给出十个数,在其下排填出对应的十个数 要求下排每个数都是先前上排那十个数在下排出现的次数。 上排的十个数如下: 【0,1,2,3,4,5,6,7,8,9】举一个例子, 数值: 0,1,2,3,4,5,6,7,8,9 分配: 6,2,1,0,0,0,1,0,0,0 0在下排出现了6次,1在下排出现了2次, 2在下排出现了1次,3在下排出现了0次.... 以此类推..
\*=====================================================*/#include <iostream>using namespace std;int scan(int *a,int *b,int length){int key = 0;for (int index = 0 ; index < length ; ++index){int sum = 0;for (int i = 0;i < length;++i){if(b[i]==a[index])++sum;}if (b[index]==sum){++key;}else{b[index] = sum;}}return key;
}void print(int *a,int length){for(int i = 0;i < length;++i){cout << a[i] << " ";}cout << endl;
}int main(){int a[10] = {0,1,2,3,4,5,6,7,8,9};int b[10] = {0,0,0,0,0,0,0,0,0,0};int length = 10;while(scan(a,b,10)!=10);print(a,length);print(b,length);return 0;
}