根据上排给出十个数,在其下排填出对应的十个数

    技术2022-05-20  31

    #include <iostream> using namespace std; int judge(int arrGiven[],int arrDest[],int len) { int flag = 0; while(!flag) { //统计第一行的元素 在第二行里出现的次数 for(int i=0;i<len;i++) { int cnt = 0; for(int j=0;j<len;j++) if(arrGiven[i]==arrDest[j]) cnt++; arrDest[i] = cnt;//注意这里必需时时更新,才能保证每次都向解靠近 } for(int i=0;i<len;i++) cout<<arrDest[i]<<" "; cout<<endl; //检查是否合格 flag = 1; for(int i=0;i<len;i++) { int count =0; for(int j=0;j<len;j++) if(arrGiven[i]==arrDest[j]) count++; if(count != arrDest[i]) { flag = 0; break; } } } return 0; } int main() { int arrGiven[]={0,1,2,3,4,5,6,7,8,9}; int arrDest[] = {0,0,0,0,0,0,0,0,0,0}; int len = 10; judge(arrGiven,arrDest,len); for(int i=0;i<len;i++) cout<<arrDest[i]<<" "; cout<<endl; system("pause"); return 0; }

    10 0 0 0 0 0 0 0 0 09 0 0 0 0 0 0 0 0 18 1 0 0 0 0 0 0 1 07 2 1 0 0 0 0 1 0 06 2 1 0 0 0 1 0 0 06 2 1 0 0 0 1 0 0 0请按任意键继续. . .


    最新回复(0)