题解 | #坐标移动#
坐标移动
https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29
#include <iostream>
using namespace std;
int main() {
int a=0,b=0;
int length=0;
int flag=0;
int count=0;
string str;
while(getline(cin,str,';'))
{
flag=0;
count=0;
length=str.size();
if(str[0]=='A')
flag=1;
else if (str[0]=='S')
flag=2;
else if (str[0]=='W')
flag=3;
else if (str[0]=='D')
flag=4;
else
continue;
for (int temp=1;temp<length;temp++)
{
if(str[temp]>='0'&&str[temp]<='9')
{
count=count*10+(str[temp]-'0');
}
else
{
flag=0;
break;
}
}
if(flag==1)
a=a-count;
if(flag==2)
b=b-count;
if(flag==3)
b=b+count;
if(flag==4)
a=a+count;
}
cout<<a<<','<<b;
}
// 64 位输出请用 printf("%lld")

查看9道真题和解析