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

谁能帮忙看看什么错误?

Posted by direfire at 2006-09-18 18:19:58 on Problem 1690
#include <iostream>
using namespace std;
#include <stdio.h>
#include <string.h>
int judge(int i, int j, char *buf)
{
	if (i==0) return 1;
	if (buf[i-1]=='(') return 1;
	if (buf[i-1]=='-') {
		int p = 0;
		for(p=i+1; p < j; p++)
			if (buf[p] == '-' || buf[p] =='+') return 0;
		return 1;
	}
	if(buf[i-1]=='+') return 1;
	
}
void go(char *buf)
{
	char res[260];
	int i, j;
	int len = strlen(buf);
	int min, max, num;
	min = max= num = 0;
	for (i = 0; i<len; i++) {
		if (buf[i] == '(') {
			num=1;
			int sign = 0;
			for (j = i+1; j <len; j++) {
				if (buf[j] == '(') num++;
				else if (buf[j] == ')')
				{
					num--;
					if (num == 0) {
						if (judge(i, j, buf)) buf[i] = buf[j] = '*';
						sign = 1;
						break;
					}
				}
			}
		}
	}
	for (i = 0; i < len; i++)
		if (buf[i] != '*') printf("%c", buf[i]);
	printf("\n");
}
int main(void)
{
	int counts = 0;
	char p;
	scanf("%d%c", &counts, &p);
	int count = 0;
	char ch;
	while(count<counts)
	{
		char buf[260];
		int i = 0;
		while(1) {
			scanf("%c", &ch);
			if (ch == '\n') {buf[i] = '\0'; break;}
			else if(ch == ' ') continue;
			else {buf[i] = ch; i++;}
		}
		go(buf);
//		printf("%s\n", buf);
		count++;
	}
	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