The day CodeSprint Ended.

I participated in CodeSprint 3. Before you judge me, let me tell you, it was a complete failure. I was hardly able to solve 1 problem out of 7 and my batchmates solved 4 problems even after starting way later when I had.

I need to keep my mind focused on Coding or I can say Bye Bye to the Placements this December.

From now on , I am focusing on solving a test placement paper or a coding competition every day . I’ll make sure I do it.I don’t think I have a option though.

BTW, Quora is damn addictive. Hats off to Adam D’Angelo.

For Now, I am solving this problem Transformation (http://ace.delos.com/usacoprob2?a=UwGQkWxSfYb&S=transform) .

WTF! I am confused now , how do we pass a 2D array of size N*N into a function ? I guess, I’ll just use dynamic allocation.

YAY! I got it working , in the 2nd Time, I did a stupid mistake in the first time. Here is my code(Include Necessary library,I’m new to blogging, don’t know how to post code 😛 ):

/*
ID: gautam11
PROG: transform
LANG: C++
*/
using namespace std;

bool Compare(char **Tiles,char **modTiles,int N)
{
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			if(Tiles[i][j]!=modTiles[i][j])
				return 0;
	return 1;
}

char** RotateBy90(char **Tiles,int N)
{
	char **modTiles;
	modTiles=(char **)malloc(sizeof(char *)*N);
	for(int i=0;i<N;i++)
		modTiles[i]=(char *)malloc(sizeof(char)*N);

	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			modTiles[i][j]=Tiles[N-1-j][i];

	return modTiles;
}
char** Reflection(char **Tiles,int N)
{
	char **modTiles;
	modTiles=(char **)malloc(sizeof(char *)*N);
	for(int i=0;i<N;i++)
		modTiles[i]=(char *)malloc(sizeof(char)*N);

	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			modTiles[i][j]=Tiles[i][N-1-j];

	return modTiles;
}
int main()
{
	freopen ("transform.in", "r", stdin);
	freopen ("transform.out", "w", stdout);
	int N;
	Sint(N);
	char **Tiles;
	Tiles=(char **)malloc(sizeof(char *)*N);
	for(int i=0;i<N;i++)
		Tiles[i]=(char *)malloc(sizeof(char)*N);
	char **finalTiles;
	finalTiles=(char **)malloc(sizeof(char *)*N);
	for(int i=0;i<N;i++)
		finalTiles[i]=(char *)malloc(sizeof(char)*N);
	for(int i=0;i<N;i++)
		scanf("%s",Tiles[i]);
	for(int i=0;i<N;i++)
		scanf("%s",finalTiles[i]);
	char **modTiles;
	modTiles=RotateBy90(Tiles,N);
	if(Compare(modTiles,finalTiles,N))
	{
		printf("1\n");
		return 0;
	}
	modTiles=RotateBy90(modTiles,N);
	if(Compare(modTiles,finalTiles,N))
	{
		printf("2\n");
		return 0;
	}
	modTiles=RotateBy90(modTiles,N);
	if(Compare(modTiles,finalTiles,N))
	{
		printf("3\n");
		return 0;
	}
	modTiles=Reflection(Tiles,N);
	if(Compare(modTiles,finalTiles,N))
	{
		printf("4\n");
		return 0;
	}
	for(int i=0;i<3;i++)
	{
		modTiles=RotateBy90(modTiles,N);
		if(Compare(modTiles,finalTiles,N))
		{
			printf("5\n");
			return 0;
		}
	}
	if(Compare(Tiles,finalTiles,N))
	{
		printf("6\n");
		return 0;
	}
	printf("7\n");	
	return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s