华为2015合肥机试

来源:互联网 发布:淘宝武汉飞鱼 编辑:程序博客网 时间:2024/04/27 20:39
//华为机试第一题:取十个数字(可重复)中不重复的最大三位数,构成最大三位数void main(){int num[10];for(int i = 0; i < 10;++i){num[i] = 0;}int index = 0;for(int i = 0; i < 10; ++i){std::cin>>index;num[index]++;}int max = 0;int count = 0;for(int i = 9; count != 3 && i >= 0; --i){if(num[i] != 0){max = max * 10 + i;count++;}}std::cout<<max<<std::endl;system("pause");}


//第二题:确定最小需要拆开盒子个数,包含多组输入//输入: <<<A>>><>//       <A>//输出: 3//       1void main(){std::string str;int arr[50];//对个数进行统计int com = 0;while(std::cin>>str){int len = str.length();int count = 0;int travel = 0;while(str[travel] != 'A' && travel != len){if(str[travel] == '(')count++;else if(str[travel] == ')')count--;travel++;}arr[com++] = count;}for(int i = 0; i < com; ++i){std::cout<<arr[i]<<std::endl;}system("pause");}


//第三题,和尚挑水,七个和尚,一周七天。每个人的安排挑水时间不同,输出所有的跳水可能排列组合//输入:0 表示该和尚当天不可挑水, 1 表示该和尚当天可挑水//输入:1 0 1 0 1 0 1//      0 1 0 1 0 1 0//      ....//输出 4//     1 2 3 5 4 6 7//     ....int stack[7];std::vector<int*> stack_record;std::set<int> mon;int count = 0;void findNext(int record[7][7],int depth){if(depth == 7){count++;int* numPtr = new int[7];for(int i = 0; i < 7; ++i){numPtr[i] = stack[i] + 1;}stack_record.push_back(numPtr);}else{for(int i = 0; i < 7;i++){if(record[i][depth] == 1 && mon.count(i) == 0){stack[depth] = i;mon.insert(i);findNext(record,depth+1);mon.erase(i);}}}}void main(){int record[7][7];for(int i = 0; i < 7; ++i){for(int j = 0; j < 7; ++j){std::cin>>record[i][j];}}findNext(record,0);std::cout<<stack_record.size()<<std::endl;for(int i = 0; i < stack_record.size(); ++i){int *tmp = stack_record[i];for(int j = 0; j < 7; ++j){std::cout<<tmp[j]<<" ";}std::cout<<std::endl;}system("pause");}


0 0