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 |
Re:请高手帮助看一下为什么总是time limited exceeded 啊?In Reply To:请高手帮助看一下为什么总是time limited exceeded 啊? Posted by:weifei at 2009-11-12 12:00:13 > #include <iostream> > > #define MAXLENGTH 100 > using namespace std; > > struct BACK > { > char URL[MAXLENGTH][75]; > int top; > }; > > struct FORWARD > { > char URL[MAXLENGTH][75]; > int top; > }; > int main() > { > struct BACK back; > struct FORWARD forward; > back.top = MAXLENGTH; > forward.top = MAXLENGTH; > if (back.top != 0) > { > back.top = back.top - 1; > strcpy(back.URL[back.top] , "http://www.acm.org/"); > } > //push("http://www.acm.org/",back); > char command[10]; > cin>>command; > while (strcmp(command , "QIUT") != 0) > { > if (strcmp(command , "VISIT") == 0) > { > char U[75]; > cin>>U; > back.top = back.top - 1; > strcpy(back.URL[back.top] , U); > //push(U,back); > cout<<back.URL[back.top]<<endl; > } > else if (strcmp(command , "BACK") == 0) > { > if ((back.top + 1) <= (MAXLENGTH - 1)) > { > forward.top = forward.top - 1; > strcpy(forward.URL[forward.top] , back.URL[back.top]); > //push(back.URL[back.top],forward); > > cout<<back.URL[back.top + 1]<<endl; > > back.top = back.top + 1; > //pop(back); > } > else > { > cout<<"Ignored"<<endl; > } > } > else if (strcmp(command , "FORWARD") == 0) > { > if (forward.top <= MAXLENGTH - 1) > { > back.top = back.top - 1; > strcpy(back.URL[back.top] , forward.URL[forward.top]); > //push(forward.URL[forward.top],back); > > cout<<forward.URL[forward.top]<<endl; > > forward.top = forward.top + 1; > //pop(forward); > } > else > { > cout<<"Ignored"<<endl; > } > } > > cin>>command; > } > return 0; > } 栈操作应该对字符串指针进行,你对整个字符串操作,肯效率会很低! Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator