Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

哪位高手帮我看看怎么Running error啊??

Posted by smilezhen at 2006-05-09 19:32:01 on Problem 2339
#include <stdio.h>

int pan (char a, char b) {
	if (a == b ) {
		return 0;
	}
	if (a == 'R') {
		if (b ==  'S') {
			return 1;
		} else {
			return -1;
		}
	}

	if (a == 'S') {
		if (b ==  'P') {
			return 1;
		} else {
			return -1;
		}
	} else {
		if (b == 'R') {
			return 1;
		} else {
			return -1;
		}
	}
}

int main(void) {
	int N, r, c, n, i, j, k, tmp, tmp1;
	char **ch1, **ch2;
	scanf ("%d", &N);
	while (N--) {
		scanf ("%d%d%d", &r, &c, &n);
		ch1 = new char *[r+1];
		ch2 = new char *[r+1];
		getchar();
		for (i=0; i<r; i++) {
			ch1[i] = new char[c+1];
			ch2[i] = new char[c+1];
			gets(ch1[i]);
		}

		for (i=0; i<n; i++) {
			for (j=0; j<r-1; j++) {
				for (k=0; k<c-1; k++) {
					tmp  = pan(ch1[j][k], ch1[j][k+1]);
					tmp1 = pan(ch1[j][k], ch1[j+1][k]);

					if (j==0 && k==0) {
						ch2[0][0] = ch1[0][0];
					}

					if (tmp == 0 || tmp1 == 0) {
						ch2[j][k] = ch1[j][k];
					}
					if (tmp == 1) {
						ch2[j][k+1] = ch1[j][k];
					}
					if (tmp1 == 1) {
						ch2[j+1][k] = ch1[j][k];
					}
					if (tmp == -1) {
						ch2[j][k] = ch1[j][k+1];
					}
					if (tmp1 == -1) {
						ch2[j][k] = ch1[j+1][k];
					}
				}
				tmp  = pan(ch1[j][k], ch1[j+1][k]);
				if (tmp == 1) {
					ch2[j][k+1] = ch1[j][k];
				} else if (tmp == -1) {
					ch2[j][k] = ch1[j][k+1];
				} else {
					ch2[j][k] = ch1[j][k];
				}
			}

			for (k=0; k<c-1; k++) {
				tmp1 = pan(ch1[j][k], ch1[j][k+1]);
				if (tmp1 == 0) {
					ch2[j][k] = ch1[j][k];
				}
				if (tmp1 == 1) {
					ch2[j][k+1] = ch1[j][k];
				}
				if (tmp1 == -1) {
					ch2[j][k] = ch1[j+1][k];
				}
			}
			tmp1 = pan(ch1[j][k], ch1[j-1][k]);
			tmp  = pan(ch1[j][k], ch1[j][k-1]);
			if (tmp == 0 && tmp1 == 0) {
				ch2[j][k] = ch1[j][k];
			}

			for (j=0; j<r; j++) {
				for (k=0; k<c; k++) {
					ch1[j][k] = ch2[j][k];
				}
			}
		}

		for (j=0; j<r; j++) {
			for (k=0; k<c-1; k++) {
				printf ("%c", ch1[j][k]);
			}
			printf ("%c\n", ch1[j][k]);
		}
		for (i=0; i<r; i++) {
			delete []ch1[i];
			delete []ch2[i];
		}
		delete []ch1;
		delete []ch2;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator