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

又是这种情况! 这题在ZJU AC了 在这里TLE 好像是读入问题?谁来帮我看看啊~ 不胜感激!!

Posted by bobobo at 2006-08-14 03:37:03 on Problem 1690
In Reply To:这题什么原因能导致tle 不是最多10组255字符? n^2也够了吧? 我晕,今天真不顺... Posted by:bobobo at 2006-08-14 03:31:53
#include<stdio.h>

char s[300];
int len;

bool shouldel(int i,int &j);

int main(){

	char enter;
	int cases;
    char ch;
	int i,j;

	scanf("%d%c",&cases,&enter);
	while(cases--){
		len=0;
		while(1){
		    scanf("%c",&ch);
			if(ch=='\n'){s[len]='\0'; break;}
			else if(ch==' ') continue;
			else s[len++]=ch;
		}

        for(i=0;i<len;i++)
			if(s[i]=='('&&shouldel(i,j)){
			    s[i]='*';
				/*
				int stack=1;
                for(j=i+1;j<len;j++){
				    if(s[j]=='(') stack++;
					else if(s[j]==')') stack--;
					if(!stack) break;
				}*/
				s[j]='*';
			}

		for(i=0;i<len;i++)
			if(s[i]!='*') printf("%c",s[i]);
		printf("\n");
		
	}

	return 0;
}

bool shouldel(int i,int &j){

	//int j;
	int stack=1;
	if(i==0){
		for(j=i+1;j<len;j++){
	        if(s[j]=='(') stack++;
		    else if(s[j]==')') stack--;
		    if(!stack) break;
		}
		return true;
	}
	else if(s[i-1]=='-'){
	
	    //int stack=1;
        int res=0;
	    for(j=i+1;j<len;j++){
	        if(s[j]=='(') stack++;
		    else if(s[j]==')') stack--;
		    else res++;
		    if(!stack) break;
		}
		if(res==1||res==0) return true;
	    else return false;
	}
    else{
	    for(j=i+1;j<len;j++){
	        if(s[j]=='(') stack++;
		    else if(s[j]==')') stack--;
		    if(!stack) break;
		}
		return true;
	}
	

}

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