题解 | #坐标移动#

坐标移动

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")

全部评论

相关推荐

哈哈哈哈哈哈哈哈哈哈这个世界太美好了
凉风落木楚山秋:毕业出路老师不管,你盖个章他好交差就完事了,等你盖完毕业了就不关他事情了
点赞 评论 收藏
分享
06-10 21:15
门头沟学院 Java
宁阿:好多这种没🧠的公司,他们估计都不知道毕业的人不能给安排实习岗
实习吐槽大会
点赞 评论 收藏
分享
06-20 17:42
东华大学 Java
凉风落木楚山秋:要是在2015,你这简历还可以月入十万,可惜现在是2025,已经跟不上版本了
我的简历长这样
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务