0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ハノイの塔 高さの概念

Posted at

'''#include

include

//詰まるところbar[バーの高さ][バーの位置]
int barbel[6][4] = { { 0,0,0,0 },{ 1,0,0,0 },{ 2,0,0,0 } ,{ 3,0,0,0 } ,{4,0,0,0},{5,0,0,0} };/こう書くとゼロクリアされる/
//やはり高さはいる
int bartakasa[3] = { 0,5,5 };

char barbel0[] = { " " };
char barbel1[] = { " # " };
char barbel2[] = { " ### " };
char barbel3[] = { " ##### " };
char barbel4[] = { " ####### " };
char barbel5[] = { " ######### " };

void move(int, int);
void syokika(void);
int takasacheck(int, int, int);
int main(void)
{
int i;
syokika();
for (i = 1; i <= 31; i++) {
printf("%d回目\n", i);
move((i&(i - 1)) % 3, ((i | (i - 1)) + 1) % 3);
syokika();
}

system("Pause");
return 0;

}
void move(int idoumoto, int idousaki)
{
int idoumototakasa = 0;
int idousakitakasa = 0;
idoumototakasa = bartakasa[idoumoto];
idousakitakasa = bartakasa[idousaki];
idoumototakasa = takasacheck(idoumototakasa, idoumoto, idousaki);

barbel[idousakitakasa][idousaki] = barbel[idoumototakasa][idoumoto];
barbel[idoumototakasa][idoumoto] = 0;

bartakasa[idousaki] = bartakasa[idousaki] - 1;
bartakasa[idoumoto] = bartakasa[idoumoto] + 1;

}
void syokika(void) {
int i;
int j;

for (i = 0; i < 6; i++) {
	for (j = 0; j < 4; j++) {
		switch (barbel[i][j]) {
			//文字列なので’が必要
		case 0:
			printf("%s", barbel0);
			break;
		case 1:
			printf("%s", barbel1);
			break;
		case 2:
			printf("%s", barbel2);
			break;
		case 3:
			printf("%s", barbel3);
			break;
		case 4:
			printf("%s", barbel4);
			break;
		case 5:
			printf("%s", barbel5);
			break;
		}
	}printf("\n");
}printf("-------------------------------------------------------\n");

}
int takasacheck(int idoumototakasa, int idoumoto, int idousaki) {

if (barbel[idoumototakasa][idoumoto] == 0)
{
	idoumototakasa = idoumototakasa + 1;
	idoumototakasa = takasacheck(idoumototakasa, idoumoto, idousaki);
}
return idoumototakasa;

}
'''

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?