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.

hanikamu.c(修正版)

Last updated at Posted at 2013-05-11
C
# include <stdio.h>
# include <stdlib.h>
# include <string.h>

enum e_move { ROW, COL };
struct position
{
	int p[2];
};

void test( const char * input, const char * ans )
{
	const char * table[9] = 
	{
		"!!!!!!!!!",	// !マークを番兵に
		"!WXYZ!!!!",
		"!VJKLa!!!",
		"!UICDMb!!",
		"!THBAENc!",
		"!!kSGFOd!",
		"!!!jRQPe!",
		"!!!!ihgf!",
		"!!!!!!!!!"	
	};
	const int move_table[][2] = { {-1,0}, {-1,-1}, {0,-1}, {1,0}, {1,1}, {0,1} };
	const struct position start = { {4,4} };	// 不要ですけど↓
	struct position pos = {0};
	char str[20] = {0};
	int i = 0;

	pos = start;				// これを試してみました(配列を構造体にしてコピー)
	strncat(str, &table[ pos.p[COL] ][ pos.p[ROW] ], 1 );
	for(i = 0; i < strlen(input); i++ )
	{
		pos.p[COL] += move_table[ input[i]-'0' ][COL];		// 移動します
		pos.p[ROW] += move_table[ input[i]-'0' ][ROW];
		strncat(str, &table[ pos.p[COL] ][ pos.p[ROW] ], 1 );
		if( table[ pos.p[COL] ][ pos.p[ROW] ] == '!' )
		{
			pos.p[COL] -= move_table[ input[i]-'0' ][COL];	// はみ出たので戻ります
			pos.p[ROW] -= move_table[ input[i]-'0' ][ROW];
		}
	}
	printf("%s\n", (strcmp(ans,str) == 0) ? "ooooo GOOD ooooo": "xxxxx BAD xxxxx");
}

int main( void )
{
	/*0*/ test( "135004", "ACDABHS" );
	/*1*/ test( "1", "AC" );
	/*2*/ test( "33333120", "AENc!!b!M" );
	/*3*/ test( "0", "AB" );
	/*4*/ test( "2", "AD" );
	/*5*/ test( "3", "AE" );
	/*6*/ test( "4", "AF" );
	/*7*/ test( "5", "AG" );
	/*8*/ test( "4532120", "AFQPOEMD" );
	/*9*/ test( "051455", "ABSHSj!" );
	/*10*/ test( "23334551", "ADMb!cdeO" );
	/*11*/ test( "22033251", "ADLKLa!ML" );
	/*12*/ test( "50511302122", "AGSjkTHTU!VW" );
	/*13*/ test( "000051", "ABHT!!!" );
	/*14*/ test( "1310105", "ACDKJW!V" );
	/*15*/ test( "50002103140", "AGSk!HU!IVIU" );
	/*16*/ test( "3112045", "AEDKYXKC" );
	/*17*/ test( "02021245535", "ABCIJW!JIHBS" );
	/*18*/ test( "014204", "ABIBCIB" );
	/*19*/ test( "255230", "ADAGAEA" );
	/*20*/ test( "443501", "AFPefgQ" );
	/*21*/ test( "022321", "ABCKLZ!" );
	/*22*/ test( "554452", "AGRh!!Q" );
	/*23*/ test( "051024", "ABSHTUH" );
	/*24*/ test( "524002", "AGAFGSB" );
	/*25*/ test( "54002441132", "AGQRjSRhRSGA" );
	/*26*/ test( "11010554312", "ACJV!!UTkSHI" );
	/*27*/ test( "23405300554", "ADMNEFOFGRi!" );
	/*28*/ test( "555353201", "AGRih!gPQG" );
	/*29*/ test( "22424105", "ADLMabaLD" );
	/*30*/ test( "11340202125", "ACJKDCKJX!!J" );
	/*31*/ test( "4524451", "AFQFPf!P" );
	/*32*/ test( "44434234050", "AFPf!!e!!Pgh" );
	/*33*/ test( "00554040132", "ABHk!j!i!jRG" );
	/*34*/ test( "3440403", "AEOePfgf" );
	/*35*/ test( "111130", "ACJW!XW" );
	/*36*/ test( "21133343125", "ADKXYZ!a!Z!L" );
	/*37*/ test( "353511", "AEFOPFA" );
	/*38*/ test( "22204115220", "ADLZYLY!KY!X" );
	/*39*/ test( "03013541", "ABABICBGB" );
	/*40*/ test( "101344", "ACIVJCA" );
	/*41*/ test( "2432541", "ADENbNdN" );
	/*42*/ test( "45332242015", "AFQPedc!!NME" );
	/*43*/ test( "215453", "ADKCAGF" );
	/*44*/ test( "45540523454", "AFQh!i!RQg!!" );
	/*45*/ test( "42434302545", "AFEOd!!ONOef" );

	return 0;
}
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?