| ||||||||||
| 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 | |||||||||
再加上递归就更爽了,贴个非常短的In Reply To:STL就是爽,把代码贴上来哈~~~~100题纪念~~~~ Posted by:yzhw at 2009-03-07 13:44:55 #include<iostream>
#include<string>
#include<list>
using namespace std;
string str;
void f(int layer, string dir)
{
int i;
list<string> fl;
for(i=0;i<layer;i++)cout<<"| ";
cout<<dir<<endl;
while(str!="]"&&str!="*")
{
if(str[0]=='f')fl.push_back(str);
else dir=str,cin>>str,f(layer+1,dir);
cin>>str;
}
fl.sort();
for(list<string>::iterator it=fl.begin();it!=fl.end();it++)
{
for(i=0;i<layer;i++)cout<<"| ";
cout<<*it<<endl;
}
}
int main()
{
for(int t=1;cin>>str,str!="#";t++)
cout<<"DATA SET "<<t<<':'<<endl,f(0,"ROOT"),cout<<endl;
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator