#include<iostream>
#include<string>
#include<math.h>
#include<vector>
#include<map>
#include<set>
using namespace std;
typedef struct point
{
int posx;
int posy;
}pos;
void SplitSting(const string& strInput, vector<string> &vec, const string& c)
{
string::size_type pos1 = 0;
string::size_type pos2 = strInput.find(c);
while(string::npos != pos2)
{
vec.push_back(strInput.substr(pos1, pos2-pos1));
pos1 = pos2 + c.size();
pos2 = strInput.find(c, pos1);
}
}
int main()
{
string input;
while(cin>>input)
{
pos pointer = {0,0};
vector<string> vecInput;
SplitSting(input, vecInput, ";");
for(int i = 0; i<vecInput.size(); i++)
{
bool isInvalid = false;
int sum=0;
if(vecInput[i].size()>1 && vecInput[i].size()<=3)
{
for(int j = 1; j <=vecInput[i].size() - 1; j++)
{
if(vecInput[i][j]>='0' && vecInput[i][j]<='9')
sum = sum*10 +(vecInput[i][j] - '0');
else
{
isInvalid = true;
break;
}
}
if(!isInvalid)
{
switch(vecInput[i][0])
{
case 'A':
pointer.posx -= sum;
break;
case 'S':
pointer.posy -= sum;
break;
case 'W':
pointer.posy += sum;
break;
case 'D':
pointer.posx += sum;
break;
default:
break;
}
}
}
}
cout<<pointer.posx<<','<<pointer.posy<<endl;
}
return 0;
}
华为机试-坐标移动
最新推荐文章于 2024-04-16 23:46:48 发布