2008-12-25
SRM405 Div1 Easy: RelativePath
class RelativePath {
public:
string makeRelative(string path, string currentDir) {
vector<string> vp = split(path,'/'), vcd = split(currentDir,'/');
int lp=sz(vp), lcd=sz(vcd);
int common=0;
if(currentDir=="/") { lcd=1; common=0;}
else
for(int i=1;i<min(lp,lcd);i++){
if(vp[i]!=vcd[i]) break;
common++;
}
string dest=""; rep(i,lcd-1-common) dest+="../";
for(int i=1+common;i<lp;i++) {dest+=vp[i];if(i<lp-1)dest+="/";}
return dest;
}
};
コメント
トラックバック - https://topcoder-g-hatena-ne-jp.jag-icpc.org/n4_t/20081225