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:放弃了,,,这题怎么做的啊,,,我的map果断tle,,,,难道要写hash,,或者trie,,,然后写一些rb树,avl之类的东西吗?500个句子就tle,,真郁闷,,?扔下我的代码,,谁帮忙看看是不是哪里死循环了?? Posted by:yy17yy at 2011-03-02 20:39:25 #include<iostream> #include<string> #include<vector> #include<algorithm> #include<sstream> using namespace std; int n; vector<string> dirs; vector<vector<string> > dir_v; void print_dir(vector<string> &v,int indent){ for(int i=indent;i<v.size();i++) cout<<string(i,' ')<<v[i]<<endl; } int main() { cin>>n; string dir; for(int i=0;i<n;i++){ cin>>dir; for(int j=0;j<dir.size();j++) if(dir[j]=='\\') dir[j]=' '; dirs.push_back(dir); } sort(dirs.begin(),dirs.end()); for(int i=0;i<n;i++){ dir_v.push_back(vector<string>()); istringstream is(dirs[i]); while(is>>dir) dir_v.back().push_back(dir); } int indent = 0; print_dir(dir_v[0],indent); for(int i=1;i<dir_v.size();i++){ indent = 0; while(indent<dir_v[i-1].size() && indent<dir_v[i].size() && dir_v[i][indent]==dir_v[i-1][indent]) indent++; print_dir(dir_v[i],indent); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator