| ||||||||||
| 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 | |||||||||
HELP me! 17061706我一直TLE,怎么一回事啊?
谢先!
#include <cstdio>
#include <string>
using namespace std;
int Getno(string temp,int &i)
{
int k=0;
for(++i;temp[i]!=']';++i)
k=k*10+temp[i]-'0';
return k;
}
bool Isempty(char *line)
{
int i;
if(line[0]==0)
return true;
for(i=0;line[i];++i)
if(line[i]!=' ')
break;
if(line[i]==0)
return true;
return false;
}
int main()
{
int ref[1000],anti[1000]={0},pref=0;
char str[100],line[100];
string refs[1000],temp;
int i,j,no;
while(gets(str))
{
while(Isempty(str) && gets(str));
if(str[0]==0)
break;
temp=str;
while(gets(line),!Isempty(line))
temp=temp+'\n'+line;
temp+='\n';
if(temp[0]=='[')
{
i=0;
no=Getno(temp,i);
refs[no]=temp.substr(i+1);
}
else
{
for(j=0;j<temp.length();++j)
if(temp[j]=='[')
{
no=Getno(temp,j);
printf("[");
if(anti[no])
printf("%d",anti[no]);
else
{
ref[pref++]=no;
anti[no]=pref;
printf("%d",pref);
}
printf("]");
}
else printf("%c",temp[j]);
printf("\n");
}
}
for(i=0;i<pref;++i)
printf("[%d]%s\n",i+1,refs[ref[i]].c_str());
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator