| ||||||||||
| 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 | |||||||||
请问这题有什么需要特别考虑的地方?为什么总是WA? 我已经改过无数次了,能考虑的都考虑到了,但还是WA。下面是我的程序,哪位高手指点一下,谢谢!
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
bool isEmpty(char* a);
void main(){
int k=0,t=0,i,j=0,s,len,u=0,f,m,p;
bool num=false,line=true,ufirst=false,rem=false;
char a[100];
char (*b)[100]=new char[40000][100]; //正文
char (*c)[1000]=new char[1000][1000]; //注释
int d[1000]; //原先注释的序号
char* cp;
for(m=0;m<1000;++m)
d[m]=0;
while(gets(a)){
rem=false;
if(isEmpty(a)){
b[k][0]='\0';//如果是空行,在正文中加一空行
++k;
continue;
}
else if((a[0]=='[')||(a[0]==' '))
rem=true;
if(rem){
if(a[0]=='['){
f=atoi(a+1);//把数字字符串转成整数
strcpy(c[f],a);
}
else{
strcat(c[f],"\n");
strcat(c[f],a);
}
b[k][0]='\0';
++k;
++t;
}
else{
for(i=1;i<strlen(a);++i){
if(a[i]=='['){
f=atoi(a+i+1);
cp=a+i+1;
if(f==0){
rem=false;
continue;
}
else rem=true;
m=0;
while((d[m]!=f)&&(m<j))
++m;
if(m==j){
d[j]=atoi(a+i+1);//按顺序存储正文中出现的注释序号
++j;
}
}
}
strcpy(b[k],a);
++k;
}
}
for(u=0;u<k;++u){
for(j=0;b[u][j]!='\0';++j){
if(b[u][j-1]=='['){
p=j;
len=atoi(b[u]+j);
if(len==0){
printf("%c",b[u][j]);
continue;
}
for(s=0;s<1000;++s){
if(len==d[s]){
printf("%d",s+1);
ufirst=true;//说明不是第一行
break;
}
}
if(b[u][j+1]!='\0')
num=true;//表示正在处理正文中的注释
}
else if(b[u][j]==']')
num=false;
if(!num){
printf("%c",b[u][j]);
ufirst=true;
}
}
if((!line)||(u==0&&ufirst)){
printf("\n");
line=true;//做标记,表示已经换行
}
if((b[u+1][j]!='\0')&&(u!=k-1))
line=false;
else if(!line)printf("\n");
}
if(b[k-1][0]!='\0')
printf("\n");
for(i=0;i<t;++i){
if(d[i]==0)
break;
printf("[%d]",i+1);
j=0;
while(c[d[i]][j]!=']')
++j;
puts(c[d[i]]+j+1);
if(d[i+1]!=0)
printf("\n");
}
delete []b;
delete []c;
}
bool isEmpty(char* a){ //判断是否是空行
int i;
for (i = 0; a[i] !='\0'; i++)
if (a[i] != ' ')
return false;
return true;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator