| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
为什么在ZJUac了,在这儿却wa了,谁能指点一下吗?#include<stdio.h>
#include<string.h>
#define max 500
char a[max];
int dig[max]={0};
int kongge();
void bt();
void fun();
int str();
void insatll();
int kongge() //去掉空格
{
int i=0,j=0,flag=0;
for(i=0;a[i]!='\0';i++)
{
if(a[i]==' ')
{
flag=1;
for(j=i;a[j]!='\0';j++)
a[j]=a[j+1];
a[j]=a[j+1]=a[j+2]='\0';
}
}
return flag;
}
void bt(void) //去掉 (a)和()的情况
{
int i;
for(i=0;a[i+2]!='\0';i++)
{
if(a[i]=='('&&a[i+2]==')')
{
a[i]=a[i+2]=' ';
}
if(a[i]=='('&&a[i+1]==')')
{
a[i]=a[i+1]=' ';
}
}
}
void fun(void) //去掉 .(..+(a+b).).等情况
{
int i,p,flag=0,count=0;
char pre='+';
for(i=0;a[i]!='\0';i++)
{
if(a[i]=='(')
{
if(flag)count++;
else
{
if(pre!='-')
{
flag=1;
p=i;
}
}
}
if(a[i]==')')
{
if(flag)
{
if(count==0)
{
a[p]=a[i]=' ';
break;
}
else
count--;
}
}
pre=a[i];
}
}
int str() //接收字符串
{
int i=0;
char temp;
while((temp=getchar())!=EOF)
{
if(temp==' ')continue;
if(temp=='\n')
{
a[i]='\0';
return 1;
}
else
a[i++]=temp;
}
return 0;
}
void install(void) //初始化,可以不要这个函数,为specials起见,就加了这个函数
{
int i;
for(i=0;i<max;i++)
a[i]='\0';
}
int main()
{
int testnum;
scanf("%d",&testnum);getchar();
while(testnum--)
{
install();
if(!str())
return 1;
bt();
while(kongge())
bt();
fun();
while(kongge())
fun();
printf("%s\n",a);
}
return 1;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator