-1
実践www.testdome.com/questions/c-sharp/path/12280?visibility=1 "パス" のための100%のスコアを取得することはできません。私は75%のスコアしか得ていません。誰かが100%スコアを得るのを手伝ってもらえますか?コードはC#の:testdome <a href="https://www.testdome.com/questions/c-sharp/path/12280?visibility=1" rel="nofollow noreferrer">https://www.testdome.com/questions/c-sharp/path/12280?visibility=1</a>上のC#の質問に
using System.Collections.Generic;
public class Path {
public string CurrentPath { get; private set; }
public Path(string path) {
this.CurrentPath = path;
}
public void Cd(string newPath) {
//absolute path
if (newPath.StartsWith("/")) {
CurrentPath = newPath;
} else if (newPath.Contains("../")) {
var pathList = new LinkedList<string>(CurrentPath.Split('/'));
var newPathList = newPath.Split('/');
foreach (var item in newPathList) {
if (item == "..") {
if (pathList.Count > 0)
pathList.RemoveLast();
} else {
pathList.AddLast(item);
}
}
CurrentPath = string.Join("/", pathList);
if (!CurrentPath.StartsWith("/"))
CurrentPath = "/" + CurrentPath;
} else {
CurrentPath += "/" + newPath;
}
}
}
Spot on!どうもありがとう。 – YDY