本帖最后由 jhq999 于 2021-12-4 12:39 编辑
只是样例思路int count=0,i=0;
//a[4]={'d','a','b','c'};
//b[4]={'d','d','d','d'};
//c[6]={'a','b','b','c','c','d'};
while(true)
{
for(i=0;i<4;i++)
{
if(a[i]==c[0])a[i]=c[1];
else if(a[i]==c[2])a[i]=c[3];
else if(a[i]==c[4])a[i]=c[5];
else continue;
count++;
}
if(*((int*)a)==*((int*)b))break;
}
这是题目的思路int count=0,prvcount=0,i=0,j=0;
//m=4
//n=3
//a[4]={'d','a','b','c'};
//b[4]={'d','d','d','d'};
//c[6]={'a','b','b','c','c','d'};
while(true)
{
for(i=0;i<m;i++)
{
for(j=0;(j<2*n)&&(a[i]!=b[i]);j+=2)
{
if(a[i]==c[j])
{
a[i]=c[j+1];
count++;
break;
}
}
}
if(prvcount==count)break;
prvcount=count;
//for(j=0;j<m;j++)if(a[j]!=b[j])break;
//if(j==m)break;
}
|