URAL 1067. Disk Tree (STL vector 使用)

来源:互联网 发布:jstor数据库怎么用 编辑:程序博客网 时间:2024/05/21 16:22

使用STL,这题就非常简单了。


#include <iostream>#include <cmath>#include <cstdio>#include <cstring>#include <algorithm>#include <queue>#include <stack>#include <map>#include <set>#include <list>#include <deque>#include <string>#define LL long long#define DB double#define SI(a) scanf("%d",&a)#define SD(a) scanf("%lf",&a)#define SS(a) scanf("%s",a)#define SF scanf#define PF printf#define MM(a,v) memset(a,v,sizeof(a))#define REP(i,a,b) for(int (i)=(a);(i)<(b);(i)++)#define REPD(i,a,b) for(int (i)=(a);(i)>(b);(i)--)#define N 509#define INF 0x3f3f3f3f#define EPS 1e-8#define bug puts("bug")using namespace std;struct nod{    string name;    vector<nod> L;    nod(string c=""){name=c;}    bool operator<(const nod t) const    {        return name<t.name;    }};int n;char ch[N];int len;void dfs(int f,nod &ans){    if(f>=len) return ;    char cc[29];    int cnt = 0;    for(int i=f;i<=len;i++)    {        if(ch[i]=='\\'||ch[i]=='\0')        {            f = i+1;            cc[cnt]='\0';            break;        }        cc[cnt++] = ch[i];    }    string c = cc;    int fin = -1;    REP(i,0,(int)ans.L.size())    {        if(ans.L[i].name==c)        {            fin = i;        }    }    if(fin==-1)    {        fin = ans.L.size();        ans.L.push_back(nod(c));    }    dfs(f,ans.L[fin]);}void format(nod &ans){    sort(ans.L.begin(),ans.L.end());    REP(i,0,(int)ans.L.size())    {        format(ans.L[i]);    }}void out(int k,nod &ans){    REP(i,0,(int)ans.L.size())    {        REP(j,0,k) PF(" ");        cout<<ans.L[i].name<<endl;        out(k+1,ans.L[i]);    }}int main(){    #ifndef ONLINE_JUDGE    freopen("in.txt","r",stdin);    #endif    SI(n);    nod ans;    while(n--)    {        SS(ch);        len = strlen(ch);        dfs(0,ans);    }    format(ans);    out(0,ans);    return 0;}

原创粉丝点击