Üben Sie die C# -Frage auf dem Testdome https://www.testdome.com/questions/c-sharp/path/12280?visibility=1. Ich bekomme nur 75% Punkte. Könnte mir jemand helfen, 100% Punkte zu bekommen? Code angebracht untenC#: Kann nicht 100% Punktzahl für "Path" erhalten www.testdome.com/questions/c-sharp/path/12280?visibility=1
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 auf! Danke vielmals. – YDY