题解 | #坐标移动#

坐标移动

https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29

#include <iostream>
#include <vector>   //牛客要包含vector

using namespace std;

class Solution{
public:
    Solution();
    void coordinate();
    void output();

private:
    vector<string> str;
    vector<int> flag = {1};
    vector<int> upper = {0};
    int x = 0;  //? 整型范围怎么计算
    int y = 0;
    // int _x = 0;
    // int _y = 0;

};

int main() {
    Solution s;
    s.coordinate();
    s.output();
    return 0;
}
// 64 位输出请用 printf("%lld")

Solution::Solution(){
    //flag.push_back(1);  //1表示有效坐标
    char c = '\0';
    int i = 0;
    string tem;
    while((c = getchar())!='\n')
        if(c!='\73') {//转义字符八进制至多三位数字表示 ? 运算顺序是什么
            if(!(('0'<=c&&c<='9')||('A'<=c&&c<='Z')))
                flag[i] =0;
            if('A'<=c&&c<='Z')
                upper[i]++;
            tem+=c;
        }
        else{
            str.push_back(tem); //数组中加入了空串
            flag.push_back(1);
            upper.push_back(0);
            i++;
            tem = "";
        }

        // if(('0'<=s[i]&&s[i]<='9')&&('A'<=s[i]&&s[i]<='Z'))

}

void Solution::coordinate(){
    int size = str.size();
    int i = 0;
    for(const string &s:str)
        if(s.size()>0&&('A'<=s[0]&&s[0]<='Z')&&flag[i]==1&&upper[i]==1){
            int n = atoi(s.substr(1).c_str());
            switch(s[0]){
                case 'A':x-=n;break;
                case 'D':x+=n;break;
                case 'S':y-=n;break;
                case 'W':y+=n;break;
            }
            i++;
        }
        else
            i++;
}

void Solution::output(){
    cout << x << "," << y;
}

全部评论

相关推荐

牛客100866号技...:把电科加粗,把电科加粗,把电科加粗,两个吊车尾的项目合并成一个,再加一个管理系统。电科✌🏻在成都面中厂手拿把掐
点赞 评论 收藏
分享
04-02 10:09
门头沟学院 Java
用微笑面对困难:这里面问题还是很多的,我也不清楚为啥大家会感觉没啥问题。首先就是全栈开发实习9个月的内容都没有java实习生的内容多,1整个技术栈没看出太核心和难点的内容,感觉好像被拉过去打杂了,而且全栈基本上很容易被毙。里面能问的bug是在太多了比如L:继承 BaseMapper 可直接使用内置方法’。请问你的 BaseMapper 是如何扫描实体类注解如果瞬时产生 100 个上传任务,MySQL 的索引设计是否会有瓶颈?你做过分库分表或者索引优化吗?全栈的内容可以针对动态难点去搞,技能特长写在下面吧,你写了这么多技能,项目和实习体现了多少?你可以在项目里多做文章然后把这个放下去,从大致来看实习不算太水,有含金量你也要写上内容针对哨兵里面的节点变化能问出一万个问题,这个很容易就爆了。
提前批简历挂麻了怎么办
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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