When I was doing a pat today, there was this one.
The basic method is to do with the list, and use the array to do the chant, the habitual first with the array to do, the result is a problem
1#include <iostream>2#include <string.h>3 using namespacestd;4 5 intMain ()6 {7 intcount, Renum;8 stringadd;9Cin>>add>>count>>Renum;Ten stringAdd1[count],add2[count],madd1[count],madd2[count]; One intMnum[count],num[count]; A for(intI=0; i<count;i++) - { -Cin>>add1[i]>>num[i]>>Add2[i]; the } - for(intI=0; i<count;i++) - { - + for(intj=0; j<count;j++) - { + if(add1[j]==add) A { atMadd1[i] =Add1[j]; -mnum[i]=Num[j]; -Madd2[i] =Add2[j]; -Add=Madd2[i]; - Break; - } in } - } to inttemp=0; + intfake =count; - while(count-renum>=0) the { * for(intI= temp,j=temp+renum-1; i<=temp+renum-1; i++,j--) $ {Panax NotoginsengAdd1[i] =Madd1[j]; -Num[i] =Mnum[j]; the } +count-=Renum; Atemp=temp+Renum; the } + for(inti=temp;i<fake;i++) - { $ $Add1[i] =Madd1[i]; -Num[i] =Mnum[i]; - } the for(intI=0; i<fake-1; i++) - {Wuyiadd2[i]=add1[i+1]; the } -add2[fake-1] ="-1"; Wu for(intI=0; i<fake;i++) - { Aboutcout<<add1[i]<<" "<<num[i]<<" "<<add2[i]<<Endl; $ } - return 0; -}
Please disregard my variable naming habits
The result is
Run Timeout I can also understand, after all, it is possible that the complexity is O (n*n), I will find a way to solve.
But what is wrong with the answer? What special circumstances did I not consider? Please find the person to teach Ah!! Thanks, man.
Above
Collapse!!! Everybody help me to see where is the problem??? Reverse of linked list