Find the number of reverse order, quick row
Public Static voidAcm1007 (intAstring[] c) {Dictionary<int,string> dic =Newdictionary<int,string>(); int[] i =New int[A]; varj =0; foreach(varIteminchc) {intK =acm1007unit (item); if(!DiC. ContainsKey (k)) {I[j]=K; J++; Dic. ADD (k, item+","); } Else{Dic[k]+ = Item +","; I[J]= -1; J++; }} qsortdiy (I,0, I.length-1); for(intJJJ =0; JJJ < I.length; jjj++) { if(I[JJJ]! =-1) {Console.Write (DIC[I[JJJ]); } } } Public Static intAcm1007unit (stringa) {intAnum =0; intCnum =0; intGnum =0; intR =0; for(inti = a.length-1; I >=0; i--) { Switch(A[i]) { Case 'A': Anum++; Break; Case 'C': R+=Anum; Cnum++; Break; Case 'G': R+ = Anum +Cnum; Gnum++; Break; Case 'T': R+ = Anum + Cnum +Gnum; Break; } } returnR; } Public Static voidQsortdiy (int[] Array,intLowintHigh ) { if(Low >=High ) { return; } intie =Qsortunit (array, low, high); Qsortdiy (array, low, ie-1); Qsortdiy (array, ie+1, high); } Private Static intQsortunit (int[] Array,intLowintHigh ) { intKey =Array[low]; while(Low <High ) { while(Array[high] >= key && high >Low ) { --High ; } Array[low]=Array[high]; while(Array[low] <= key && high >Low ) { ++Low ; } Array[high]=Array[low]; } Array[low]=key; returnHigh ; }
c#c# ACM poj1007