[ create a new paste ] login | about

Link: http://codepad.org/gowKDlWo    [ raw code | output | fork ]

hoaithu.melody - C++, pasted on Mar 9:
//Palindrome
#include <iostream>
#include <conio.h>

using namespace std;
int main()
{
	int length;
	char c[8][8];
	freopen("Testcase.txt", "r", stdin);
	for(int testcase = 1; testcase <= 10; testcase++)
	{
		int count = 0;
		int i, j;
		cin >> length;
		for(i = 0; i < 8; i++)
			for(j = 0; j < 8; j++)
				cin >> c[i][j];

		for(i = 0; i < 8; i++)
			for(j = 0; j < 8 - length + 1; j++)
			{
				if(c[i][j] == c[i][j+length-1])
				{
					int flag = 1;
					int k = j+1;
					int l = j+length-2;
					while(k < l)
					{
						if(c[i][k] == c[i][l])
						{
							flag = 1;
							k++;
							l--;
						}
						else
						{
							flag = 0;
							break;
						}
					}
					if(flag == 1)
					count++;
				}

				if(c[j][i] == c[j+length-1][i])
				{
					int flag = 1;
					int k = j+1;
					int l = j+length-2;
					while(k < l)
					{
						if(c[k][i] == c[l][i])
						{
							flag = 1;
							k++;
							l--;
						}
						else
						{
							flag = 0;
							break;
						}
					}
					if(flag == 1)
					count++;
				}
			}
		cout << "#" << testcase << " " << count << endl;
	}
	getch();
	return 0;
}


Output:
1
2
3
4
Line 18: error: conio.h: No such file or directory
In function 'int main()':
Line 71: error: 'getch' was not declared in this scope
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: