https://www.nowcoder.com/questionTerminal/119bcca3befb405fbe58abe9c532eb29
public class Program {
public static void Main() {
string line;
while ((line = System.Console.ReadLine ()) != null) { // 注意 while 处理多个 case
string[] tokens = line.Split(";");
var point=new CPoint();
int dis;
foreach(var token in tokens)
{
if (token.Length<2||token.Length>3)continue;
if (int.TryParse(token.Substring(1),out dis))
{
point.Move(token[0],dis);
}
}
System.Console.WriteLine(point.ToString());
}
}
}
public class CPoint
{
private int x=0;
private int y=0;
public void Move(char dir,int dis)
{
if(dir=='A')
x-=dis;
else if(dir=='D')
x+=dis;
else if(dir=='W')
y+=dis;
else if(dir=='S')
y-=dis;
}
public override string ToString()
{
return x.ToString()+","+y.ToString();
}
}
标签:int,编程,牛客,token,ToString,坐标,public,dir,dis From: https://www.cnblogs.com/zhangdezhang/p/17817252.html