题解 | #求长方体表面积#

坐标移动

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

#include<bits/stdc++.h>
using namespace std;
//字符串是否合法,第一个是字母,剩下有且仅有是数字
//如何实现分号分割
bool mov(string str){
    bool stard = true;
    if(str.length()<=1) stard = false;
    for(auto it=str.begin()+1; it!=str.end();++it){
        if(!((*it>='0'&&*it<='9')||*it == ';')){
            stard = false;
            break;}
    }
    return stard;
}
int move(string str){
    string num;
    if((str[0]=='A'||str[0]=='D'||str[0]=='W'||str[0]=='S')&&mov(str)){
        for(auto it=str.begin()+1; it!=str.end();++it){
            num.push_back(*it);
        }
    }
    return atoi(num.c_str());
}

int main(){
    string strTemp,strInput,temp="";
    int x=0,y=0;
    cin>>strTemp;
    vector<string> myVec;
    for(auto s:strTemp){
        if(s!=';'){
            temp+=s;
        }
        else{
            myVec.push_back(temp);
            temp = "";
        }
    }
    
    for(auto strInput:myVec){
        
        //
        if(strInput[0]=='A'){
            x-=move(strInput);
        }
        else if(strInput[0]=='D'){
            x+=move(strInput);
        }
        else if(strInput[0]=='W'){
            y+=move(strInput);
        }
        else if(strInput[0]=='S'){
            y-=move(strInput);
        }
    }
    cout<<x<<","<<y<<endl;
    
    return 0 ;
}
全部评论

相关推荐

身边有人上海、深圳&nbsp;6、7k&nbsp;都去了,真就带薪上班了。
程序员小白条:木的办法, 以后越来越差,还是家附近宅着吧,毕业的人越来越多,岗位都提供不出来,经济又过了人口红利期
点赞 评论 收藏
分享
zYvv:双一流加大加粗再标红,然后广投。主要是获奖荣誉不够,建议开始不用追求大厂,去别的厂子刷下实习。
点赞 评论 收藏
分享
07-03 11:02
中山大学 C++
字节刚oc,但距离九月秋招很近了有两段互联网实习,非腾讯字节。不敢赌转正,现在在纠结去还是不去如果实习俩月离职会有什么后果吗
阿城我会做到的:不去后悔一辈子,能否转正取决于ld的态度,只要他不卡,答辩就是走流程,个人觉得可以冲一把
投递字节跳动等公司8个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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