Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

其实很简单,排个序一扫就行了

Posted by Liuzhaoliang at 2014-10-07 12:03:23 on Problem 1760
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator