坐标移动

来源:互联网 发布:单片机软件工程师招聘 编辑:程序博客网 时间:2024/05/22 06:11
#include<bits/stdc++.h>using namespace std;bool check1(char c){    if(c=='A'||c=='W'||c=='S'||c=='D')return true;    return false;}bool check2(char c){    if(c<='9'&&c>='0')return true;    return false;}int main(){    char a[100000];    while(cin>>a)    {        int x=0,y=0;        char *p;        p=strtok(a,";");        while(p)        {            if(strlen(p)>=2&&strlen(p)<=3&&check1(p[0])&&check2(p[1]))            {                if(strlen(p)==3&&check2(p[2]))                {                    if(p[0]=='A')                    {                        x-=(p[1]-'0')*10+(p[2]-'0');                    }                    else if(p[0]=='D')                    {                        x+=(p[1]-'0')*10+(p[2]-'0');                    }                    else if(p[0]=='S')                    {                        y-=(p[1]-'0')*10+(p[2]-'0');                    }                    else if(p[0]=='W')                    {                        y+=(p[1]-'0')*10+(p[2]-'0');                    }                }                else if(strlen(p)==2)                {                    if(p[0]=='A')                    {                        x-=p[1]-'0';                    }                    else if(p[0]=='D')                    {                        x+=p[1]-'0';                    }                    else if(p[0]=='S')                    {                        y-=p[1]-'0';                    }                    else if(p[0]=='W')                    {                        y+=p[1]-'0';                    }                }            }            p=strtok(NULL,";");        }        cout<<x<<","<<y<<endl;    }}

原创粉丝点击