LINUX.ORG.RU

История изменений

Исправление alysnix, (текущая версия) :

где то так короче. основная идея.

void move(){
	int holes[]={2,3,4};
	int data[]={100,100,100,100,100,100,100};
		
	const int holesLen = 3;
	const int dataLen = 7;
	
	
	int h0 = 0, h1 = holesLen-1;
	int i = dataLen-1;
		
	while (h0<=h1){
		if (i <= holes[h1]) {
			if(i==holes[h1]) --i;
                        --h1;
 			continue;
		}
		//he we can move the righmost element
		data[holes[h0++] = data[i--]];
	}
}

Исходная версия alysnix, :

где то так короче. основная идея.

void move(){
	int holes[]={2,3,4};
	int data[]={100,100,100,100,100,100,100};
		
	const int holesLen = 3;
	const int dataLen = 7;
	
	
	int h0 = 0, h1 = holesLen-1;
	int i = dataLen-1;
		
	while (h0<=h1){
		if (i <= holes[h1]) {
			--h1; 
			if(i==holes[h1]) --i;
			continue;
		}
		//he we can move the righmost element
		data[holes[h0++] = data[i--]];
	}
}